Binding a controls enabled property to a static class property based on a separate threads state
-
I have a method that queues a number of processes in a separate thread, long running stored procs. I want to disable controls and warn the user that the thread is still active so they cannot close the application while the thread is running. I have a static class (clsMain) that has the property and the change event that is set from within the processing thread.
public static event EventHandler ProcessFlagChanged; private static bool \_IsProcessing; public static bool IsProcessing { get { return \_IsProcessing; } set { \_IsProcessing = value; if (ProcessFlagChanged != null) ProcessFlagChanged(null, EventArgs.Empty); } }
I now want to bind a buttons enabled value to clsMain.IsProcessing. This naturally does not work because clsMain is a type.
btnLoadPool.DataBindings.Add(new Binding("Enabled", clsMain, "IsProcessing"));
Is the design flawed or do I need to have another variable/event on the form to bind to?
Never underestimate the power of human stupidity RAH
-
I have a method that queues a number of processes in a separate thread, long running stored procs. I want to disable controls and warn the user that the thread is still active so they cannot close the application while the thread is running. I have a static class (clsMain) that has the property and the change event that is set from within the processing thread.
public static event EventHandler ProcessFlagChanged; private static bool \_IsProcessing; public static bool IsProcessing { get { return \_IsProcessing; } set { \_IsProcessing = value; if (ProcessFlagChanged != null) ProcessFlagChanged(null, EventArgs.Empty); } }
I now want to bind a buttons enabled value to clsMain.IsProcessing. This naturally does not work because clsMain is a type.
btnLoadPool.DataBindings.Add(new Binding("Enabled", clsMain, "IsProcessing"));
Is the design flawed or do I need to have another variable/event on the form to bind to?
Never underestimate the power of human stupidity RAH
Why do you choose a static class? If you drop the statics and instantiate it, all would be well. And if you only want to have one instance at most, look for the singleton pattern. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
-
Why do you choose a static class? If you drop the statics and instantiate it, all would be well. And if you only want to have one instance at most, look for the singleton pattern. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
Luc Pattyn wrote:
Why do you choose a static class?
Well, because it's already there. I do want to reference this from at least 3 different places but that is a minor issue.
Never underestimate the power of human stupidity RAH
-
Luc Pattyn wrote:
Why do you choose a static class?
Well, because it's already there. I do want to reference this from at least 3 different places but that is a minor issue.
Never underestimate the power of human stupidity RAH
smells like static abuse. OO requires you explicitly pass a reference around for the objects you want to use. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
-
smells like static abuse. OO requires you explicitly pass a reference around for the objects you want to use. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
Luc Pattyn wrote:
smells like static abuse
Yeah, yeah, where are my global variables, I'll revert to variant shortly. Did the job properly, declared a class, passed the class from the main form to the processing form, used a BGW thread to do the work and everything hangs together nicely. I don't use a lot of threading, I live behind the firewall and don't use a WAN, so latency is rarely an issue. This is slowly changing and the move to Silverlight is going to be interesting!
Never underestimate the power of human stupidity RAH