|
I just installed VS 2005 on my Vista Machine and when the project runs it doesn't allow me to break point. Inside visual studios it is sitting ready to be run again. Does anyone know how I can get get the debugger to work. Thanks a million.
|
|
|
|
|
Are you running VS with administrator rights?
Me: Can you see the "up" arrow?
User:Errr...ummm....no.
Me: Can you see an arrow that points upwards?
User: Oh yes, I see it now!
-Excerpt from a support call taken by me, 08/31/2007
|
|
|
|
|
Thanks Martin. That did the trick.
|
|
|
|
|
You're welcome.
Me: Can you see the "up" arrow?
User:Errr...ummm....no.
Me: Can you see an arrow that points upwards?
User: Oh yes, I see it now!
-Excerpt from a support call taken by me, 08/31/2007
|
|
|
|
|
I would like to display a custom message box form as a modal dialog by calling Form.ShowDialog(this). However, I would like to make this call from a separate thread in my main class. Currently when I do this, upon exiting the second form (which is displayed correctly), my entire application locks up. I have put some sample code below which illustrates the problem...
public class MainForm : Form {
...
private void Button1_Click(object sender, EventArgs e) {
new Thread(new ThreadStart(showModalDialogThread)).Start();
}
private void showModalDialogThread() {
ModalDialog myDialog = new ModalDialog();
myDialog.ShowDialog(this); // freezes the application on close event
}
}
public class ModalDialog : Form { ... }
Thanks ahead of time to anyone who can help,
Jeff
|
|
|
|
|
You can't show a modal dialog for your application on a separate thread. Because you are passing "this" in as the parent windows, the message box must be created and shown on the same thread that the parent window was created on.
What exactly are you trying to accomplish?
Take care,
Tom
-----------------------------------------------
Check out my blog at http://tjoe.wordpress.com
|
|
|
|
|
I currently have a threaded process that loads a file in the background, but it shows dialogs in a number of situations using the "MessageBox.Show(this, ...)" method (works as expected) to notify the user of progress/errors. However, a few of the dialogs present messages that are far too long to show in a standard MessageBox, so I made a new class called MessageBoxExtended, which looks and feels identical to the built-in MessageBox, with similar parameters and everything. On my class I have a static method (Show) that you can send the same parameters as in MessageBox.Show. However, when I call my static method (MessageBoxExtended.Show(this, message, caption)) from the same place I called the other, I get complete lock-up when I try to close my dialog. Since the built-in MessageBox works fine for this, I don't understand why there is no way for me to implement the same functionality. I tried to use owner.Invoke() within my MessageBoxExtended.Show() method, but that freezes up on loading. Any other ideas, or are you certain there is no way to do this?
Jeff
|
|
|
|
|
I would suggest that you create delegates/events to accomplish this. for example:
to show progress :
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
Import imp = new Import();
public Form1()
{
InitializeComponent();
imp.ProgressChanged += new ProgressChangedEventHandler(imp_ProgressChanged);
}
protected void imp_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
this.progressBar1.Maximum = e.Total;
this.progressBar1.Value = e.CurrentProgress;
}
private void button1_Click(object sender, EventArgs e)
{
Thread thrd = new Thread(new ThreadStart(imp.Start));
thrd.Start();
}
}
}
//Your Delegate
public delegate void ProgressChangedEventHandler(object sender, ProgressChangedEventArgs e);
//Your ProgressChangedEventArgs event
public class ProgressChangedEventArgs : EventArgs
{
//Fields
private int _currentProgress;
private int _total;
//Constructors
public ProgressChangedEventArgs(int currentProgress, int total)
{
this._currentProgress = currentProgress;
this._total = total;
}
//Properties
public int CurrentProgress
{
get { return this._currentProgress; }
}
public int Total
{
get { return this._total; }
}
}
//Import Class
public class Import
{
//Events
public ProgressChangedEventHandler ProgressChanged;
//Method
public void Start()
{
int tot = 1000;
for (int i = 0; i < tot; i++)
{
OnProgressChanged(this, new ProgressChangedEventArgs(i, tot));
Thread.Sleep(100);
}
}
//Event Method
protected void OnProgressChanged(object sender, ProgressChangedEventArgs e)
{
ISynchronizeInvoke sync = (ISynchronizeInvoke)this.ProgressChanged.Target;
if (sync.InvokeRequired) {
ProgressChangedEventHandler tmp = new ProgressChangedEventHandler(OnProgressChanged);
object[] args ={ sender, e };
sync.Invoke(tmp, args);
return;
}
if (ProgressChanged != null)
ProgressChanged(sender, e);
}
}
-- modified at 13:28 Friday 12th October, 2007
|
|
|
|
|
OK. I have come up with a painful, yet operable, solution. In every single static "Show" method that could get called in my MessageBoxExtended class, I do the following...
public static DialogResult Show(IWin32Window owner, ...) {
Control parent = owner as Control;
if (parent != null && parent.InvokeRequired) {
return (DialogResult)parent.Invoke(new SpecificDelegate(MessageBoxExtended.Show),
new object[] { parent, ... });
} else {
return (new MessageBoxExtended(...)).ShowDialog(owner);
}
}
Every "..." in the previous (and following) code is filled in with identical arguments with what is passed in. This works, but I am confused why the following does not...
public static DialogResult Show(IWin32Window owner, ...) {
Control parent = owner as Control;
MessageBoxExtended mbe = new MessageBoxExtended(...);
if (parent != null && parent.InvokeRequired) {
return (DialogResult)parent.Invoke(new ShowDialogDelegate(mbe.ShowDialog),
new object[] { parent });
} else {
return (new MessageBoxExtended(...)).ShowDialog(owner);
}
}
Does anyone have any insight as to why the hell the first method works as expected but the second freezes?! My head feels like it is about to explode (and I am sad becuase I have to add like 50 delegates to my class)!
Jeff (More confused than I have ever been)
|
|
|
|
|
Hi Jeff,
Since Controls are not thread-safe, the basic rule is: the thread that creates a Control
is the only thread that is allowed to access the Control (with the exception of a few
members such as InvokeRequired and Invoke).
Since most often all Controls are related (part of Form.Controls, parent to each other, etc),
this normally means only one (the main) thread will create and access Controls.
the first method is OK.
the second fails because another thread creates mbe, then asks the creator of owner
(probably the main thread) to access mbe.
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- use PRE tags to preserve formatting when showing multi-line code snippets
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
That makes perfect sense! Thank you very much for the straightforward and descriptive answer! My head hurts less now. I sure wish that I could just do overloaded methods like in C++ (with default values) so I only had to make one change instead of like 200. Thanks for the advice in the following post as well.
Jeff
|
|
|
|
|
One more thing, you don't need as many delegates as MessageBox.Show() has overloads.
Within your MessageBoxExtended class you could map most of them onto the most powerful one,
then let that one perform the InvokeRequired/Invoke stuff.
And you could shortcircuit that for the most popular overload(s) adding some delegates and
code again to improve performance, although this is probably irrelevant since MessageBoxes
typically block your thread anyway until the user decides to close them.
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- use PRE tags to preserve formatting when showing multi-line code snippets
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
I need some help getting base data from an object.
Here is the code that I am using:
l_oAttributes = type.GetCustomAttributes(true);<br />
<br />
foreach (Attribute attribute in l_oAttributes)<br />
{<br />
Object l_oTest = l_oAttributes[0];<br />
}
etc etc...
The information I need is in the base of the l_oTest (ie ColumeID and such), how can I access this information?
Thanks
|
|
|
|
|
RussBus wrote: how can I access this information
I guess l_oTest is a type other than Object so you need to cast it and then access it's public members, or am I missing something?
|
|
|
|
|
Do I cast it as the type of attribute it is? How would I do this?
|
|
|
|
|
If you know the base type of l_oTest, simply convert it to that type...
KnownBaseType kt = l_oTest as KnownBaseType;
if (kt != null) {
// Do Something
}
If you don't know what the base type is, but you know you want to get or set the value of some property, use reflection...
using System.Reflection;
...
PropertyInfo pi = l_oTest.GetType().BaseType.GetProperty("PropertyName");
if (pi.CanRead) {
PropertyReturnType result = (PropertyReturnType)pi.GetGetMethod().Invoke(l_oTest, null);
}
Is this what you need?
Jeff
|
|
|
|
|
I still don't get the value.
I want to get the value for ColumnID, when I use you code I get ColumnID but not the value for it.
|
|
|
|
|
NM you are a programming god, your code works
|
|
|
|
|
Post the part of your code that isn't working like you need it to, and explain exactly what you expect or need to get from it so I can help further.
Jeff
|
|
|
|
|
I am writing a small program in C# that has to count the number of image files and the number of text files in a single folder and to come up with a seperate value for each type of file. The code has to be general enough to accomodate changes to the number of image or text files in a given folder depending upon the designated path.
At present, my approach has been to specify the path via code such as @"C:\My Program\Folder";
Any help would be appreciated.
|
|
|
|
|
Read the first thread in the forum titled "How to get an answer to your question". Pay attention to item #2
|
|
|
|
|
if you know the file type, the easiest way is use Directory.GetFiles(path, "*.ext"); it will return a string array, you can get the file count using Properties of Length
|
|
|
|
|
Thank you so much.
As I said before, I am on this like you can't believe.
|
|
|
|
|
Then you can use System.Drawing.Imaging.ImageCodecInfo.GetImageEncoders(); to get all supported image format, or you could create your own image format array to loop the extension as I mention(and what you did).
|
|
|
|
|
You people are great!
I have solved much of the program's display requirements... thanks to all of your assistance and pointers.
|
|
|
|