|
-
February 19th, 2003, 02:19 AM
#1
Using a form in Windows Service
Hi.
I'm trying to use a windows form in my Service app.
Can anyone please tell me how to do this.
I'm trying to call the form in the "OnStart" function in the service.
-
February 19th, 2003, 01:02 PM
#2
you need to include the dlls and references, using statements that are already required in usual windowsForm application. so u need to copy all those ......
best is make a normal windows app and compair what u haven't got.
Paresh
-
February 19th, 2003, 01:14 PM
#3
Thanx for your reply.
I think I've allready done that.
The problem is that the form is shown but it "hangs" and doesn't accept any inputs and isn't fully painted???????
/mabj
-
February 19th, 2003, 01:18 PM
#4
hi
the problem is when windows service starts it starts in thread ! I would rather suggest you not to open a form. normally windows services are process/memory based.
the another problem with form is when
you run the form
it needs something like this
Application.run(...form.....)
may be u can try that.
but remember concepts of services are diff. and they need to be in handled in specific way like opening file etc..
you can have another form/windows app seperately interacting with this service
and getting thru-fro the data ..
have a service socket based and have a form client based thus u can access the data. i am sure there are otherways of
doing this also.
Paresh
-
February 19th, 2003, 01:29 PM
#5
I know what you mean. Normaly a service would'nt have any forms. But in this case this app needs in some cases som user input.
I was trying to come up with a way to have a windows app to handle the userinput and to interact with the service (calling some functions in the service app) but it seems to be quite difficult, or?
I thought that I could create an instance of the form in the service app and simply call Form.Show(). I've also tried to create a new thread to run the form but the result would be the same.
Any Idea of a way to have a Windows app to comunicate with the service? Using Winsock will not work in this case.
/mabj
-
February 19th, 2003, 01:33 PM
#6
TCPClient or .NET sockets should work. if you use it properly then it should be fine. since what happens is service waits for a while to complete the thread.
so u can have a form like this.
open a thread in the form finish the thread and in that thread open the form. note here form object should be public. and make that open.. so it won't distroy..
Paresh
-
February 19th, 2003, 04:08 PM
#7
I don't think I quite understand what you mean by your last reply.
Isn't there any sample code somewhere that will show this?
-
February 19th, 2003, 04:10 PM
#8
what I meant was,
when you have a onstart on service ! right.
then you can start a thread which will open a form. this thread will just open the form and complete.
now this form stays open till the class is live. or form is canceled. shouldn't be hard.
Paresh
-
February 19th, 2003, 04:22 PM
#9
I might be incredible stupid and still don’t understand.
As I described earlier I have tried to create a new thread in the OnStart section and using this thread to load the Form.
If that is what you are trying to explain this doesn’t work (not the way I’m doing it). The form is displayed, yes, but it freezes and it seems that no part of the code in the Form class is executing. You can’t even close the form.
-
February 20th, 2003, 05:51 AM
#10
Never mind.
I've got what you mean and I've got it to work.
Thanks for your help Paresh
-
February 20th, 2003, 05:19 PM
#11
oh! that's pretty cool. I was just about to write a windows service program and try that out. glad to know.
Paresh
-
July 23rd, 2003, 01:29 AM
#12
Windows form in service
I read all the post regarding this,i created a thread in OnStart method and in that thread tried to create a message box ,what is the difference b/w any form and a message box if a form can be created in that thread why not a message box?
i tried to do that but even when service gets started successfullly,Message box is not visible.
i don't know why?
anticipating an earliest reply
regards
Anushree
-
July 24th, 2003, 05:09 AM
#13
hi,
A difference between executing a Windows service and other Visual Studio .NET applications is that the dialog boxes raised from a Windows service are not visible to the user. In addition, the error messages generated from a Windows service are logged in the event logs.
so u can't see message box generated from the windows service, I don't about forms.
Ashish Sheth
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|