Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / September 2005

Tip: Looking for answers? Try searching our database.

HELP: Non-Responding Application

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
WJScott69@Yahoo.com - 30 Sep 2005 03:48 GMT
I have written an application in C# and have everything I want working
except when I kick off the query to other machines VIA WMI it hangs
the app until it completes or I kill it. I know in VB there is a
fuction to use to allow the GUI to be interactive 9Move the window,
Cance by clicking a buttonm etc.) Is there such a function in C# to
unfreez the app I have and need desperatly to respond!!!
Mark R. Dawson - 30 Sep 2005 12:47 GMT
Hi WJScott,
 the problem you are seeing is due to the fact that you are using the main
UI thread to perform a syncronous action that takes time to complete.  While
this is running the UI thread has to wait and cannot perform the task of
updating the UI.

 I would recommend running your long task in another thread, this way the
UI will still be responsive while the task is happening.  Once the other
threads task has completed you can update the GUI - remember to call invoke
though on the control not update the GUI directly from the non UI thread i.e.

using System;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;

namespace WindowsApplication3
{
   public class Form1 : Form
   {
       public Form1()
       {
           InitializeComponent();
       }

       private void Form1_Load(object sender, EventArgs e)
       {
           Thread worker = new Thread(new ThreadStart(DoLongTask));
           worker.IsBackground = true;
           worker.Start();
       }

       private void DoLongTask()
       {
           //This will pause the worker thread, not the main
           //UI thread
           System.Threading.Thread.Sleep(10000);

           label1.Invoke(new LabelUpdateDelegate(UpdateLabel));
       }

       private void UpdateLabel()
       {
           this.label1.Text = "ALL DONE";
       }

       private delegate void LabelUpdateDelegate();
   }
}

Hope that helps
Mark R Dawson
http://www.markdawson.org

> I have written an application in C# and have everything I want working
> except when I kick off the query to other machines VIA WMI it hangs
> the app until it completes or I kill it. I know in VB there is a
> fuction to use to allow the GUI to be interactive 9Move the window,
> Cance by clicking a buttonm etc.) Is there such a function in C# to
> unfreez the app I have and need desperatly to respond!!!

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.