|
I've had similar issues, apparently the debug runtime handles exceptions generated across threads (any gui app has a minumum of 2, gui and main) differently than the releasemode runtime. You need to move your exception handler into a method and attach it to the thread exception handler. Leave your try catch in place, you'll still need it to handle any exceptions generated by static classes. Even if your current implementation doesn't have any, since this is obscure and wierd behavior I'd cover it now and document why I had both ways in place.
Application.ThreadException += new ThreadExceptionEventHandler (FatalExceptionHandler);
|
|
|
|
|
You just became my personal superhero!
Your solution does excactly what I want, and is so simple
Thank you very much.
Greatings,
Djohnnie
|
|
|
|
|
Glad to be of help. I was in your shoes a few months ago.
|
|
|
|
|
If I create a default static constuctor.
Can I be guaranteed that this will be called the first time a static property or method is called?
Thanks,
Nick
1 line of code equals many bugs. So don't write any!!
|
|
|
|
|
It will be called the first time the class is loaded, so, basically, the answer to your question is yes.
--------
"I say no to drugs, but they don't listen."
- Marilyn Mansonques
|
|
|
|
|
thanks
1 line of code equals many bugs. So don't write any!!
|
|
|
|
|
|
He was asking "what time is it?", not "how does your watch work?"
--------
"I say no to drugs, but they don't listen."
- Marilyn Manson
|
|
|
|
|
How mundane!
|
|
|
|
|
Here's the situation:
I have 5 classes. Each class has various properties.
Example:
WindowLocation class ->
Contains properties for my main app's location, as well as other windows.
MenuOptions class ->
Contains properties for my menus. Show check margin, etc.. things like that.
No point listing them all but you get the idea.
I have them organized like this so I can simply type...
MenuOptions.ShowCheckMargin = mnuItemShowCheckMargin.Checked;
etc.
I have absolutely no idea how to save all the classes to 1 single XML file using Serialization (then read the file with serialization and set my properties up to value contained in the XML file). I looked at a million examples, and none of them apply to what I'm trying to do.
I can't put it all together, this is after days of on/off research.
I simply want all the classes to have their properties stored in 1 XML file.
Structured like this:
[Settings]
[WindowLocations]
[Main]
[X]0[/X]
[Y]0[/Y]
[/Main]
[Options]
[X]0[/X]
[Y]0[/Y]
[/Options]
[/WindowLocations]
[MenuOptions]
[ShowCheckMargin]true[/ShowCheckMargin]
[UseXPStyle]false[/UseXPStyle]
[/MenuOptions]
[/Settings]
(Note: Replace [] with HTML brackets...board screwed them up)
|
|
|
|
|
First of all, if you want your data to be serialize to the same file, the easiest way is to put all of your classes in the same container class (i.e. appSettingsMemory). Then it's all a matter of serializing this class to disk. You have to be aware of certain principles of serialization but a quick google search whould put enough light on your problems.
I might publish an article on this subject on my website soon so you may want to check it out at www.digitalGetto.com.
Good Luck
"color: rgba(0, 0, 255, 1)"__^ cXYPosition
{
^__b style="color: blue"__^public int</b__^ X;
^__b style="color: blue"__^public int Y;
}
^__b style="color: blue"__^public struct cWindowLocations
{
^__b style="color: blue"__^public <font style="color: teal">cXYPosition</font> Main;
^__b style="color: blue"__^public <font style="color: teal">cXYPosition</font> Options;
}
^__b style="color: blue"__^public struct cMenuOptions
{
^__b style="color: blue"__^public bool ShowCheckMargin;
^__b style="color: blue"__^public bool UseXPStyle;
}
^__b style="color: blue"__^public <font style="color: teal">cWindowLocations</font> WindowLocations;
^__b style="color: blue"__^public <font style="color: teal">cMeenuOptions</font> MenuOptions;
^__b style="color: blue"__^public appSettingsMemory()
{
^__i__^
WindowLocations.Main.X = 0;
WindowLocations.Main.Y = 0;
WindowLocations.Options.X = 0;
WindowLocations.Options.Y = 0;
MenuOptions.ShowCheckMargin = true;
MenuOptions.UseXPStyle = false;
}
}
^__b style="color: blue"__^public void DumpToFile(<font style="color: teal">appSettinsMemory</font> mem, ^__b style="color: blue"__^string FilePath)
{
^__b style="color: blue"__^try
{
^__b style="color: blue"__^using (<font style="color: teal">FileStream</font> fs = ^__b style="color: blue"__^new <font style="color: teal">FileStream</font>(FilePath, FileMode.Create))
{
<font style="color: teal">XmlSerializer</font> xs = ^__b style="color: blue"__^new <font style="color: teal">XmlSerializer</font>(^__b style="color: blue"__^typeof(<font style="color: teal">appSettingsMemory</font>));
xs.Serialize(fs, mem);
fs.Close();
}
}
^__b style="color: blue"__^catch (<font style="color: teal">Exception</font> e)
{
^__i__^
<font style="color: teal">MessageBox</font>.Show(e.Message);
}
}
^__b style="color: blue"__^public <font style="color: teal">appSettinsMemory</font> LoadFromFile(^__b style="color: blue"__^string FilePath)
{
<font style="color: teal">appSettingsMemory</font> mem = ^__b style="color: blue"__^new <font style="color: teal">appSettinsMemory</font>();
^__b style="color: blue"__^try
{
^__b style="color: blue"__^using (<font style="color: teal">FileStream</font> fs = ^__b style="color: blue"__^new <font style="color: teal">FileStream</font>(FilePath, FileMode.Open))
{
<font style="color: teal">XmlSerializer</font> xs = ^__b style="color: blue"__^new <font style="color: teal">XmlSerializer</font>(^__b style="color: blue">typeof(<font style="color: teal">appSettinsMemory</font>));
mem = (<font style="color: teal">appSettinsMemory</font>)xs.Deserialize(fs);
fs.Close();
}
}
^__b style="color: blue">catch (<font style="color: teal">Exception</font> e)
{
^__i>
}
^__b style="color: blue">return mem;
}
----
www.digitalGetto.com
-- modified at 15:33 Tuesday 20th June, 2006 (added De-serialization code and color formatting)
|
|
|
|
|
Thank a bunch for helping me out. Quick question though.
In my main app I'm creating an instance of the appSettingsMemory class.
appSettingsMemory settings = new appSettingsMemory();
Then, just doing this for all the properties:
settings.MenuOptions.ShowCheckMargin = ...
On exit, I'm saving settings:
settings.DumpToFile(settings);
This is working fine. It's saving all the data to the file (for each of my properties).
Problem is loading. When I load the settings, none of my program's options are getting set to what they are in the XML file.
I'm doing a settings.Load() before I run my routine that sets the program's options to their value.
this.Location = settings.WindowLocations.Main;
etc..
-- modified at 17:15 Tuesday 20th June, 2006
Edit:
Scratch that I see what's happening now. I have to set that new instance to what Load() returns. Great, it's all working perfectly now. Thx again, looking forward to your article.
|
|
|
|
|
I have a form with several components. After I selected options from couple of listboxes i then click on a button to perform an infinite loop. my problem is that while the application still running, i want to make a new choice of my option, and then hit the run button again. but since im application is in a loop it doesn't response spontaneously to my action on the form.
What is a good way to solve this kind of problem?
Donkaiser
|
|
|
|
|
If you want your UI thread to stay responsive, then you will have to put your loop in a separate thread.
----------------------------
Be excellent to each other
EasiReports[^] My free reporting component for WinForms.
|
|
|
|
|
This looks like a typical case which multitherading can play a role in. Here is my take and see if it makes sense.
When you click the "run" (which I call it) button, start a thread. Place the infinite loop in the thread function. This should guarantee that the form still responds to your click while the infinite loop is looping.
In order for your infinite loop to accept new selections made by the user, there should be some data exchange between the main thread and your looping thread. This has to be done through some thread synchronization mechanisms, say, critical section or mutex.
In short, multithreading is a good way to solve your problem.
Best,
Jun
|
|
|
|
|
thank you. I was leaning toward multithread. but im surprised because in vb5 (which is older) we don't need to worry about this kinda problem.
Donkaiser
|
|
|
|
|
donkaiser wrote: but im surprised because in vb5 (which is older) we don't need to worry about this kinda problem.
What? If VB5 didn't have this 'problem', then it's because the loop was being run on a different thread behind the scenes. It's not really a problem; if you think about it logically, it's a natural outcome: one thread is flooded with work, so it cannot be bothered to do other tasks such as repainting the control or responding to user input. Therefore, long running tasks should not be run on the UI thread if you want a responsive UI.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Goof around music jam with my brothers (with video)
The apostle Paul, modernly speaking: Epistles of Paul
Judah Himango
|
|
|
|
|
Have you try putting Application.DoEvents() in the loop?
|
|
|
|
|
I have datagrid with a dataset set as the DataSource. I have added a X number of tables to the dataset, but when I view my datagrid it shows all the tables in the datagrid but I can only view the first table. The other tables don't show when I click or navigate onto them.
How do I get it to open or view the other tables?
<br />
DataSet dataset = new DataSet("Sms Report");<br />
dataset.Tables.Add(sendItemsTable);<br />
<br />
packagesTables = new DataTable[sendItemsTable.Rows.Count];<br />
for(int i = 0; i < distinctPackagesTable.Rows.Count; i++)<br />
{<br />
packagesTables[0] =
}<br />
<br />
if(packagesTables.Length > 0)<br />
dataset.Tables.AddRange(packagesTables);<br />
<br />
dataset.AcceptChanges();<br />
<br />
dataGrid.DataSource = dataset;<br />
dataGridStyle1.MappingName = dataGrid.DataMember;<br />
dataGrid.Expand(0);<br />
Leon v Wyk
|
|
|
|
|
I would like to automating Team Foundation Server to have a console app get the latest on a list of projects.
Does anyone have a link on achieving this task?
1 line of code equals many bugs. So don't write any!!
-- modified at 12:37 Tuesday 20th June, 2006
|
|
|
|
|
How can protect against reverse engineering and hacking in .Net?
obfescation and generic encription is not enough?
thanks
Yigal
|
|
|
|
|
Google: international patent
|
|
|
|
|
Hello I was wondering if in C# we have something equivalent to this timer loop:
'loop for .1 second
Duration! = Timer + 0.1
Do Until Timer > Duration!
Dummy = DoEvents()
Loop
Donkaiser
|
|
|
|
|
I don't know what behavior that produces in VB5, thankfully.
I imagine something like this might do:
System.Threading.Thread.Sleep(0);
That suspends the current thread to allow waiting threads to execute
System.Threading.Thread.Sleep(100);
That specifies a "minimum" of 100 milliseconds but it could be longer I believe.
If I get flamed for answering a VB question you owe me! Last modified: Tuesday, June 20, 2006 10:13:30 AM --
|
|
|
|
|
how to add dynamic control in C#.net and how to store dynamic textbox control value to the database.
|
|
|
|