T
Theresa Smallwood
Is there a way to add a Windows MessageLoop to an existing thread? I have a
..NET application that is called from from a COBOL app using COM, and when I
show a form, the System.Windows.Forms.Application.MessageLoop is set to
false. Is there some way to ensure that the form displayed has a
MessageLoop?
I have tried displaying the form several ways (described below), but all of
them seem to have some problem that makes it a less then ideal solution.
Showing the form this way:
System.Windows.Forms.Application.Run(_child);
Worked great, except that the user couldn't get back to COBOL application
that launched the .NET form - and we needed to be able to do that.
So I tried this:
ShowFormDelegate formshow = new ShowFormDelegate(ShowFormMessageLoop);
this.AppContext.CurrentWorkbench.Form.Invoke(formshow, new object[]
{_child});
Where ShowFormMessageLoop is:
private void ShowFormMessageLoop(Form frm)
{
frm.Show();
}
(Where this.AppContext.CurrentWorkbench.Form is a form that is not visible,
in fact it's never visible, it's just created in the background. )
But this does not have a MessageLoop, so Tabs, ESC, function keys, etc. are
not processed at all on the form.
This method came the closest to working correctly, except that some of the
3rd party controls (grids and toolbars) that were on the forms would not
process keystrokes correctly - the controls are apparently implementing a
message filter that is not getting processed.
_applicationcontext = new System.Windows.Forms.ApplicationContext(_child);
ThreadStart _threadstart = new ThreadStart(this.StartMessageLoop);
Thread _thread = new Thread(_threadstart);
_thread.IsBackground = true;
_thread.ApartmentState = ApartmentState.STA;
_thread.Start();
Where StartMessageLoop is:
private void StartMessageLoop()
{
System.Windows.Forms.Application.Run(_applicationcontext);
}
If anyone has any ideas, I would greatly appreciate it. Thanks!
Theresa
..NET application that is called from from a COBOL app using COM, and when I
show a form, the System.Windows.Forms.Application.MessageLoop is set to
false. Is there some way to ensure that the form displayed has a
MessageLoop?
I have tried displaying the form several ways (described below), but all of
them seem to have some problem that makes it a less then ideal solution.
Showing the form this way:
System.Windows.Forms.Application.Run(_child);
Worked great, except that the user couldn't get back to COBOL application
that launched the .NET form - and we needed to be able to do that.
So I tried this:
ShowFormDelegate formshow = new ShowFormDelegate(ShowFormMessageLoop);
this.AppContext.CurrentWorkbench.Form.Invoke(formshow, new object[]
{_child});
Where ShowFormMessageLoop is:
private void ShowFormMessageLoop(Form frm)
{
frm.Show();
}
(Where this.AppContext.CurrentWorkbench.Form is a form that is not visible,
in fact it's never visible, it's just created in the background. )
But this does not have a MessageLoop, so Tabs, ESC, function keys, etc. are
not processed at all on the form.
This method came the closest to working correctly, except that some of the
3rd party controls (grids and toolbars) that were on the forms would not
process keystrokes correctly - the controls are apparently implementing a
message filter that is not getting processed.
_applicationcontext = new System.Windows.Forms.ApplicationContext(_child);
ThreadStart _threadstart = new ThreadStart(this.StartMessageLoop);
Thread _thread = new Thread(_threadstart);
_thread.IsBackground = true;
_thread.ApartmentState = ApartmentState.STA;
_thread.Start();
Where StartMessageLoop is:
private void StartMessageLoop()
{
System.Windows.Forms.Application.Run(_applicationcontext);
}
If anyone has any ideas, I would greatly appreciate it. Thanks!
Theresa