Click here to Skip to main content
15,920,111 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
I have function in my Windows Form and now I'm trying to transfer my work to windows service, After transferring I notice that InvokeRequired and BeginInvoke are not supported by windows service
Posted

1 solution

You must be talking about System.Windows.Forms.Control.Invoke and System.Windows.Forms.Control.Invoke. These methods are specific to this Forms library and have nothing to do with Windows Services. The delegate the invocation of any delegate instances the Form UI thread. I explained them in my past answers:
Control.Invoke() vs. Control.BeginInvoke()[^],
Problem with Treeview Scanner And MD5[^].

A Service does not have a UI thread, so this stuff it totally inapplicable to it. If, by some reason, you would need to delegate some delegate instance invocation to some different thread, this thread should be appropriately designed to accept those invocation request from some queue. You can learn how it work from my article:
Simple Blocking Queue for Thread Communication and Inter-thread Invocation[^].

I must say, at least in some part of your work you take a wrong route. You should not try "translate" some application from one application type to another application type, especially if you don't clearly understand some techniques or things like this invocation mechanism. Instead, you should start from decomposing the original product into parts by aspects. First of all, you need to isolate UI, the part with never "survives" porting from one application type to another. (In your case, Windows Services don't have UI at all.) Actually, you need to thoroughly separate UI from other aspects of you product in first place, when you create this product, not when you port it.

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900