Form could be invisible - just hide it on load for example. Show your status
window from MainForm.Load.
CreateWindowEx). Btw, this one could be used to transform your MainForm into
message-only window. It has some limitations, but could work for you too.
"Serge" <serge_knecht@hotmail.com> wrote in message
news:3fa66335$0$1873$ba620e4c@reader0.news.skynet.be...
> Thanks 100
> That helps me a lot. I already read about this message loop a couple of
time
> but now it's slowly all coming together.
>
> Now just for the test I followed your suggestion and added the
> Application.Run to my code so that the message loop would be started.
> Specifically i added in my static Main method (from the class that is
> defined as start object) the Application.Run line.
> The problem I have here is that the code from Main method after the
> Application.Run line is only executed when the form is closed again. And
> that is not what I want.
>
> I can not simply add this code in the form.
> The reason for this is that this form is a simple status window.
> It is shared by all my applications and contains no intelligent code. It
> just displays the progress of the application.
> The real work is done in the classes that are set as the start-up object.
>
> So now I need a way to figure out how to start my application from my
class
> and still start this form's message loop using the application.run line.
> Do you know a way ?
> I can think of some solution using delegates but don't know if this is the
> best practise.
>
> Thanks in advance for your suggestions,
>
> Regards,
>
> Serge
>
>
> "100" <100@100.com> wrote in message
> news:%23uQU5y$nDHA.2456@TK2MSFTNGP09.phx.gbl...
> > Hi Serge,
> >
> > Application will hang for sure. When you use the Main method in Class1
as
> a
> > start point. There is no code starting the message loop
(Application.Run).
> > At least Control.Invoke uses messages to switch the execution over the
UI
> > thread. Further more if there is no message loop you cannot move,
resize,
> > close or do anything with the form. Form is freezed on the screen. It
> won't
> > even repaint itself.
> >
> > What you might want to do is.
> > 1. Remove
> > _frmStatus.Show();
> > _frmStatus.Refresh();
> > from the code. You don't need them.
> > 2. Insted of
> > while(true)
> > {
> > Thread.Sleep(1000);
> > }
> >
> > put the following:
> > System.Windows.Forms.Application.Run(_frmStatus);
> >
> > That makes the code almost like the one you have in the form's class.
> >
> > HTH
> > B\rgds
> > 100
> >
> >
> >
> > "Serge" <serge_knecht@hotmail.com> wrote in message
> > news:3fa2d1e6$0$22162$ba620e4c@reader3.news.skynet.be...
> > > Hi,
> > >
> > > I am having a thread hang problem in my c# code.
> > >
> > > The example on the website:
http://csharp.web1000.com/ is a
> > > simplified version of my problem.
> > >
> > > You will see in the form that a method TestThread increments a number
in
> > the
> > > textbox on the form.
> > > TestThread is called from a worker thread (2nd thread) using a
> > TimerThread.
> > > Every 2 seconds it will increment the number in te text box.
> > >
> > > First start the project from the form (form1 class is the startup
> object).
> > > The Form is displayed. Now push the button, this will create the
> > > TimerThread.
> > > You now see nicely that the number increments every 2 seconds.
> > >
> > > Now start the application from the class (class1 is the startup
object).
> > > Now the TimerThread will be created in the Class1 object.
> > > You will see that the number is never incremented.
> > >
> > > When stepping through the code you will see that the TestThread method
> is
> > > called.
> > > The TestThread code in the form properly detects that this is run from
a
> > > second thread (line InvokeRequired) and continues to the line where
> Invoke
> > > is called. I use Invole so that the increment function would run on
the
> > > forms thread. It is here where the application seems to hang. The
number
> > in
> > > the textbox is never incremented.
> > >
> > > Can anyone explain me why this is happening or how to solve this ?
> > > i was wondering, might this have something to do with
> Apparementthreading
> > ?
> > > (this is used when you start the application from the form (=startup
> > > object)).
> > > Maybe when you start it from the class this is no longer the case ?
> > > Maybe it's something completely different.
> > > Thanks for shedding some light in the darkness.
> > >
> > > Regards, Serge
> > >
> > >
> > >
> > >
http://csharp.web1000.com/ > > >
> > >
> >
> >
>
>