Click here to Skip to main content
15,889,843 members
Home / Discussions / C#
   

C#

 
GeneralRe: How to get ConfigurationSettings for multiple users Pin
Asad Hussain25-Apr-05 10:59
Asad Hussain25-Apr-05 10:59 
Generalprevious article on copying windows explorer functionality Pin
Anonymous25-Apr-05 9:08
Anonymous25-Apr-05 9:08 
GeneralRe: previous article on copying windows explorer functionality Pin
Polis Pilavas26-Apr-05 1:55
Polis Pilavas26-Apr-05 1:55 
QuestionSerialPort(framwork2) is freezing when closing? Pin
Snowjim25-Apr-05 8:10
Snowjim25-Apr-05 8:10 
AnswerRe: SerialPort(framwork2) is freezing when closing? Pin
Snowjim25-Apr-05 8:14
Snowjim25-Apr-05 8:14 
GeneralRe: SerialPort(framwork2) is freezing when closing? Pin
Snowjim25-Apr-05 8:36
Snowjim25-Apr-05 8:36 
GeneralSecondary message loop Pin
Luis Alonso Ramos25-Apr-05 7:48
Luis Alonso Ramos25-Apr-05 7:48 
GeneralRe: Secondary message loop Pin
S. Senthil Kumar25-Apr-05 19:06
S. Senthil Kumar25-Apr-05 19:06 
I suspect that's because StartProcess is called from a thread that already has a message loop. Are you calling start in response to an UI action, like clicking a button? In that case, the call to StartProcess comes on a thread that has a message loop, so when you call Application.Run again, it throws an exception.

form.ShowDialog should work fine. Are you sure you are using Invoke/BeginInvoke when trying to access method/properties on progressFrom from within WorkerThread? If you are not using Invoke/BeginInvoke, the UI won't be updated properly. form.Show should also work fine, as it is called from a thread running a message loop.

The solution then is to remove the line that calls Application.Run and make sure you use Invoke/BeginInvoke like
void StartProcess()
{    
    ProgressForm form = new ProgressForm();
    WorkerClass wc = new WorkerClass(progressForm, delegate and so on);
    Thread t = new Thread(new ThreadStart(wc.Run));
    t.IsBackgroundThread = true;
    form.Show();
    t.Start();
    return;
}

class WorkerThread
{
   ProgressForm progressForm;
   public WorkerThread(ProgressForm progressForm) {...}
   public void Run()
   {
       while (true)
       {
           progressForm.UpdateStatus();
       }
   }
}

class ProgressForm
{
   private delegate void EmptyParametersDelegate();
   public void UpdateStatus()
   {
      if (this.InvokeRequired)
      {
         // Marshal the call to the UI thread. This method will be called
         // again on the UI thread and on that invocation, InvokeRequired
         // will be false.
         this.Invoke(new EmptyParametersDelegate(UpdateStatus), null);
         return;
      }
      // Do the actual UI update here
      this.progressBar.Value = x;
   }
} 

Regards
Senthil
_____________________________
<font face="Verdana" size="1"><a href="http://blogs.wdevs.com/senthilkumar">My Blog</a> | <a href="http://www.codeproject.com/script/articles/list_articles.asp?userid=492196">My Articles</a> | <a href="http://geocities.com/win_macro">WinMacro</a></font>

GeneralCompile differences in file and memory Pin
machocr25-Apr-05 7:15
machocr25-Apr-05 7:15 
GeneralHello All -- Some Problem In C# Pin
OMSSD8425-Apr-05 6:43
OMSSD8425-Apr-05 6:43 
GeneralRe: Hello All -- Some Problem In C# Pin
Polis Pilavas25-Apr-05 8:46
Polis Pilavas25-Apr-05 8:46 
GeneralRe: Hello All -- Some Problem In C# Pin
OMSSD8425-Apr-05 20:01
OMSSD8425-Apr-05 20:01 
GeneralRe: Hello All -- Some Problem In C# Pin
Polis Pilavas26-Apr-05 1:32
Polis Pilavas26-Apr-05 1:32 
GeneralHide the command window Pin
Sheela Krishnan25-Apr-05 6:15
Sheela Krishnan25-Apr-05 6:15 
GeneralRe: Hide the command window Pin
Steven Campbell25-Apr-05 6:24
Steven Campbell25-Apr-05 6:24 
GeneralRe: Hide the command window Pin
Dave Kreskowiak25-Apr-05 8:25
mveDave Kreskowiak25-Apr-05 8:25 
GeneralRe: Hide the command window Pin
Sheela Krishnan25-Apr-05 11:20
Sheela Krishnan25-Apr-05 11:20 
GeneralAbout Resource File Pin
SAMURAI-MAN25-Apr-05 5:35
SAMURAI-MAN25-Apr-05 5:35 
GeneralOpening a specified folder; double-clickon system tray icon Pin
Anonymous25-Apr-05 5:33
Anonymous25-Apr-05 5:33 
GeneralRe: Opening a specified folder; double-clickon system tray icon Pin
Polis Pilavas25-Apr-05 8:53
Polis Pilavas25-Apr-05 8:53 
GeneralRe: Opening a specified folder; double-clickon system tray icon Pin
mav.northwind25-Apr-05 20:24
mav.northwind25-Apr-05 20:24 
GeneralExport generated data to database. Pin
StoneWolfSoft25-Apr-05 5:22
StoneWolfSoft25-Apr-05 5:22 
GeneralObject reference not set to an instance of an object. On Marshal.PtrToStructure Method Pin
mrxero25-Apr-05 4:44
mrxero25-Apr-05 4:44 
GeneralSaving socket connection information Pin
CheckDude25-Apr-05 4:27
CheckDude25-Apr-05 4:27 
GeneralRe: Saving socket connection information Pin
S. Senthil Kumar26-Apr-05 2:31
S. Senthil Kumar26-Apr-05 2:31 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.