Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Windows Forms
  4. Binding a controls enabled property to a static class property based on a separate threads state

Binding a controls enabled property to a static class property based on a separate threads state

Scheduled Pinned Locked Moved Windows Forms
wpfwcfdesignquestion
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mycroft Holmes
    wrote on last edited by
    #1

    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

    L 1 Reply Last reply
    0
    • M Mycroft Holmes

      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

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      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.

      M 1 Reply Last reply
      0
      • L Luc Pattyn

        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.

        M Offline
        M Offline
        Mycroft Holmes
        wrote on last edited by
        #3

        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

        L 1 Reply Last reply
        0
        • M Mycroft Holmes

          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

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #4

          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.

          M 1 Reply Last reply
          0
          • L Luc Pattyn

            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.

            M Offline
            M Offline
            Mycroft Holmes
            wrote on last edited by
            #5

            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

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups