Click here to Skip to main content
15,892,575 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
i have a boolean parameterized method which returns t/f.
i want to call that method from windows services and run it repeatedly.
i m calling it on start but some issue is coming.
Plz guide me to a nice level so that i can do it smoothly.
Posted
Comments
[no name] 30-Apr-13 9:33am    
You would need to be a bit more specific than "some issue".

1 solution

The problem of passing anything to/from a thread from/to another thread are easily solved by using a proper thread wrapper. Please see my past answers:
How to pass ref parameter to the thread[^],
Change parameters of thread (producer) after it is started[^],
MultiThreading in C#[^].

Can you see the idea? First, you obtain access to the whole instance of the wrapper class from the thread method, because you actually pass the whole reference to the instance, "this", without a need for typecasting. Secondly, you can properly encapsulate the access to the wrapper instance from the other thread, in particular, encapsulate the locks and guarantee that you cannot break proper locking of shared objects by the bug in the using code.

One warning for you: don't rush to say "this is not my problem", first think at my solution thoroughly. You did not specify your problem accurately, to start with. My solution is for a wide range of similar problems. Anyway, your clarifications or follow-up questions are welcome.

—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