Pause Code While Form Processes Without Using Modal

K

Ken Brannigan

Hello,
I have a Class Library that contains a windows form and a public class. The
public class has a static method that creates a windows form and uses some
of its functionality. I need the statis method to pause while the form does
its processing. When the form is done the code in the static method will
finish and return control to the user. I can not display it modally because
this is not allowed when a DLL is being used by say ASP.NET. I have tried
using a seperate thread but after the Form.Show executes the method finishes
and hence the thread dies before the form does its work. I have also tried
using the AutoResetEvent class but when the WaitOne method is called
everything just freezes since it is all on the same thread. I am currently
doing a tight loop with alow of Application.DoEvents and constantly checking
to see if form is finished. I HATE DOING IT THAT WAY!! There must be a way I
can do this!! Please any help would be greatly appreciated!!!

Sample:

public static void RunForm()
{
Main mainForm = null;

mainForm = new Main();
mainForm.Left = 100;
mainForm.Show();

//WAIT UNTIL FORM FINISHES PROCESSING.

mainForm.Close();
mainForm.Dispose;
mainForm = null;
}

Thank you for any help!!!
Ken
 
D

Dmitriy Lapshin [C# / .NET MVP]

Hello Ken,

If the code in the form class is just some logic or calculations, the best
solution would be to move that code out of the form.

If the code in the form class does something visual, it shouldn't be used
from ASP .NET code. Judging by your code, the latter is the case.
 
K

Kenneth H. Brannigan

Dmitriy,
The code uses a control that creates some files for us and the control can
not live without a windows form. It sucks but nothing I can do about it. Any
help is appreciated.
Thanks,
Ken

Dmitriy Lapshin said:
Hello Ken,

If the code in the form class is just some logic or calculations, the best
solution would be to move that code out of the form.

If the code in the form class does something visual, it shouldn't be used
from ASP .NET code. Judging by your code, the latter is the case.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

Ken Brannigan said:
Hello,
I have a Class Library that contains a windows form and a public class. The
public class has a static method that creates a windows form and uses some
of its functionality. I need the statis method to pause while the form does
its processing. When the form is done the code in the static method will
finish and return control to the user. I can not display it modally because
this is not allowed when a DLL is being used by say ASP.NET. I have tried
using a seperate thread but after the Form.Show executes the method finishes
and hence the thread dies before the form does its work. I have also tried
using the AutoResetEvent class but when the WaitOne method is called
everything just freezes since it is all on the same thread. I am currently
doing a tight loop with alow of Application.DoEvents and constantly checking
to see if form is finished. I HATE DOING IT THAT WAY!! There must be a
way
I
can do this!! Please any help would be greatly appreciated!!!

Sample:

public static void RunForm()
{
Main mainForm = null;

mainForm = new Main();
mainForm.Left = 100;
mainForm.Show();

//WAIT UNTIL FORM FINISHES PROCESSING.

mainForm.Close();
mainForm.Dispose;
mainForm = null;
}

Thank you for any help!!!
Ken
 
D

Dmitriy Lapshin [C# / .NET MVP]

Hmm, are you sure it cannot? Most controls can be instantiated as regular
classes and their non-UI functionality can be consumed that way. Could you
name the control? (my blind guess is that it is a some kind of Rich Text
Control).

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

Kenneth H. Brannigan said:
Dmitriy,
The code uses a control that creates some files for us and the control can
not live without a windows form. It sucks but nothing I can do about it. Any
help is appreciated.
Thanks,
Ken

Dmitriy Lapshin said:
Hello Ken,

If the code in the form class is just some logic or calculations, the best
solution would be to move that code out of the form.

If the code in the form class does something visual, it shouldn't be used
from ASP .NET code. Judging by your code, the latter is the case.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

Ken Brannigan said:
Hello,
I have a Class Library that contains a windows form and a public
class.
The
public class has a static method that creates a windows form and uses some
of its functionality. I need the statis method to pause while the form does
its processing. When the form is done the code in the static method will
finish and return control to the user. I can not display it modally because
this is not allowed when a DLL is being used by say ASP.NET. I have tried
using a seperate thread but after the Form.Show executes the method finishes
and hence the thread dies before the form does its work. I have also tried
using the AutoResetEvent class but when the WaitOne method is called
everything just freezes since it is all on the same thread. I am currently
doing a tight loop with alow of Application.DoEvents and constantly checking
to see if form is finished. I HATE DOING IT THAT WAY!! There must be a
way
I
can do this!! Please any help would be greatly appreciated!!!

Sample:

public static void RunForm()
{
Main mainForm = null;

mainForm = new Main();
mainForm.Left = 100;
mainForm.Show();

//WAIT UNTIL FORM FINISHES PROCESSING.

mainForm.Close();
mainForm.Dispose;
mainForm = null;
}

Thank you for any help!!!
Ken
 
K

Ken Brannigan

Hey Dmitriy,
Sorry I should have mentioned the control earlier. It is the web browser
control. I tried to use it without a windows form but it was a no go.
Thanks,
Ken

Dmitriy Lapshin said:
Hmm, are you sure it cannot? Most controls can be instantiated as regular
classes and their non-UI functionality can be consumed that way. Could you
name the control? (my blind guess is that it is a some kind of Rich Text
Control).

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

Kenneth H. Brannigan said:
Dmitriy,
The code uses a control that creates some files for us and the control can
not live without a windows form. It sucks but nothing I can do about it. Any
help is appreciated.
Thanks,
Ken

in message news:%23i%[email protected]...
Hello Ken,

If the code in the form class is just some logic or calculations, the best
solution would be to move that code out of the form.

If the code in the form class does something visual, it shouldn't be used
from ASP .NET code. Judging by your code, the latter is the case.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

Hello,
I have a Class Library that contains a windows form and a public class.
The
public class has a static method that creates a windows form and
uses
some
of its functionality. I need the statis method to pause while the form
does
its processing. When the form is done the code in the static method will
finish and return control to the user. I can not display it modally
because
this is not allowed when a DLL is being used by say ASP.NET. I have tried
using a seperate thread but after the Form.Show executes the method
finishes
and hence the thread dies before the form does its work. I have also tried
using the AutoResetEvent class but when the WaitOne method is called
everything just freezes since it is all on the same thread. I am currently
doing a tight loop with alow of Application.DoEvents and constantly
checking
to see if form is finished. I HATE DOING IT THAT WAY!! There must be
a
way
I
can do this!! Please any help would be greatly appreciated!!!

Sample:

public static void RunForm()
{
Main mainForm = null;

mainForm = new Main();
mainForm.Left = 100;
mainForm.Show();

//WAIT UNTIL FORM FINISHES PROCESSING.

mainForm.Close();
mainForm.Dispose;
mainForm = null;
}

Thank you for any help!!!
Ken
 
D

Dmitriy Lapshin [C# / .NET MVP]

I remember I has been able to use that one without a form in VB6. The only
problem was that there was no way to disable JavaScript other than changing
the IE options affecting all instances of the browser.
If you could tell what you are trying to accomplish, I would then be
probably able to suggest a workaround.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

Ken Brannigan said:
Hey Dmitriy,
Sorry I should have mentioned the control earlier. It is the web browser
control. I tried to use it without a windows form but it was a no go.
Thanks,
Ken

Dmitriy Lapshin said:
Hmm, are you sure it cannot? Most controls can be instantiated as regular
classes and their non-UI functionality can be consumed that way. Could you
name the control? (my blind guess is that it is a some kind of Rich Text
Control).

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

Kenneth H. Brannigan said:
Dmitriy,
The code uses a control that creates some files for us and the control can
not live without a windows form. It sucks but nothing I can do about
it.
Any
help is appreciated.
Thanks,
Ken

in message Hello Ken,

If the code in the form class is just some logic or calculations,
the
best
solution would be to move that code out of the form.

If the code in the form class does something visual, it shouldn't be used
from ASP .NET code. Judging by your code, the latter is the case.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

Hello,
I have a Class Library that contains a windows form and a public class.
The
public class has a static method that creates a windows form and uses
some
of its functionality. I need the statis method to pause while the form
does
its processing. When the form is done the code in the static
method
will
finish and return control to the user. I can not display it modally
because
this is not allowed when a DLL is being used by say ASP.NET. I have
tried
using a seperate thread but after the Form.Show executes the method
finishes
and hence the thread dies before the form does its work. I have also
tried
using the AutoResetEvent class but when the WaitOne method is called
everything just freezes since it is all on the same thread. I am
currently
doing a tight loop with alow of Application.DoEvents and constantly
checking
to see if form is finished. I HATE DOING IT THAT WAY!! There must
be
 
K

Kenneth H. Brannigan

Dmitriy,
Thanks for the responses so far. Once we load a page into the browser
control we are taking a screen shot of its contents and writing out a
graphics file.
Thanks,
Ken


Dmitriy Lapshin said:
I remember I has been able to use that one without a form in VB6. The only
problem was that there was no way to disable JavaScript other than changing
the IE options affecting all instances of the browser.
If you could tell what you are trying to accomplish, I would then be
probably able to suggest a workaround.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

Ken Brannigan said:
Hey Dmitriy,
Sorry I should have mentioned the control earlier. It is the web browser
control. I tried to use it without a windows form but it was a no go.
Thanks,
Ken

in message news:[email protected]...
Hmm, are you sure it cannot? Most controls can be instantiated as regular
classes and their non-UI functionality can be consumed that way. Could you
name the control? (my blind guess is that it is a some kind of Rich Text
Control).

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

Dmitriy,
The code uses a control that creates some files for us and the
control
can
not live without a windows form. It sucks but nothing I can do about it.
Any
help is appreciated.
Thanks,
Ken

in message Hello Ken,

If the code in the form class is just some logic or calculations, the
best
solution would be to move that code out of the form.

If the code in the form class does something visual, it shouldn't be
used
from ASP .NET code. Judging by your code, the latter is the case.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

Hello,
I have a Class Library that contains a windows form and a public
class.
The
public class has a static method that creates a windows form and uses
some
of its functionality. I need the statis method to pause while
the
form
does
its processing. When the form is done the code in the static method
will
finish and return control to the user. I can not display it modally
because
this is not allowed when a DLL is being used by say ASP.NET. I have
tried
using a seperate thread but after the Form.Show executes the method
finishes
and hence the thread dies before the form does its work. I have also
tried
using the AutoResetEvent class but when the WaitOne method is called
everything just freezes since it is all on the same thread. I am
currently
doing a tight loop with alow of Application.DoEvents and constantly
checking
to see if form is finished. I HATE DOING IT THAT WAY!! There
must
 
D

Dmitriy Lapshin [C# / .NET MVP]

Hmm... you could do that in a separate WinForms application launched by the
Web page. The application, however, should be run under a user who can
access the desktop.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

Kenneth H. Brannigan said:
Dmitriy,
Thanks for the responses so far. Once we load a page into the browser
control we are taking a screen shot of its contents and writing out a
graphics file.
Thanks,
Ken


Dmitriy Lapshin said:
I remember I has been able to use that one without a form in VB6. The only
problem was that there was no way to disable JavaScript other than changing
the IE options affecting all instances of the browser.
If you could tell what you are trying to accomplish, I would then be
probably able to suggest a workaround.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

Ken Brannigan said:
Hey Dmitriy,
Sorry I should have mentioned the control earlier. It is the web browser
control. I tried to use it without a windows form but it was a no go.
Thanks,
Ken

in message Hmm, are you sure it cannot? Most controls can be instantiated as regular
classes and their non-UI functionality can be consumed that way.
Could
you
name the control? (my blind guess is that it is a some kind of Rich Text
Control).

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

Dmitriy,
The code uses a control that creates some files for us and the control
can
not live without a windows form. It sucks but nothing I can do
about
it.
Any
help is appreciated.
Thanks,
Ken

"Dmitriy Lapshin [C# / .NET MVP]"
wrote
in message Hello Ken,

If the code in the form class is just some logic or
calculations,
the
best
solution would be to move that code out of the form.

If the code in the form class does something visual, it
shouldn't
be
used
from ASP .NET code. Judging by your code, the latter is the case.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

Hello,
I have a Class Library that contains a windows form and a public
class.
The
public class has a static method that creates a windows form and
uses
some
of its functionality. I need the statis method to pause while the
form
does
its processing. When the form is done the code in the static method
will
finish and return control to the user. I can not display it modally
because
this is not allowed when a DLL is being used by say ASP.NET. I have
tried
using a seperate thread but after the Form.Show executes the method
finishes
and hence the thread dies before the form does its work. I
have
also
tried
using the AutoResetEvent class but when the WaitOne method is called
everything just freezes since it is all on the same thread. I am
currently
doing a tight loop with alow of Application.DoEvents and constantly
checking
to see if form is finished. I HATE DOING IT THAT WAY!! There
must
be
a
way
I
can do this!! Please any help would be greatly appreciated!!!

Sample:

public static void RunForm()
{
Main mainForm = null;

mainForm = new Main();
mainForm.Left = 100;
mainForm.Show();

//WAIT UNTIL FORM FINISHES PROCESSING.

mainForm.Close();
mainForm.Dispose;
mainForm = null;
}

Thank you for any help!!!
Ken
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top