在Windows服务中的线程上传递一个布尔参数化方法 [英] pass a boolean parameterized method on thread in windows services

查看:64
本文介绍了在Windows服务中的线程上传递一个布尔参数化方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个布尔参数化方法,返回t / f。

i想从Windows服务中调用该方法并重复运行。

im在启动时调用它但有些问题即将到来。

Plz引导我达到一个很好的水平,这样我就可以顺利完成。

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.

推荐答案

传递。请看我过去的答案:

如何将ref参数传递给线程 [ ^ ],

更改线程(生产者)启动后的参数 [ ^ ],

C#中的多线程 [ ^ ]。



你能看到这个想法吗?首先,您可以从thread方法获取对包装类的整个实例的访问权限,因为您实际上将整个引用传递给实例this,而无需进行类型转换。其次,您可以正确地封装来自其他线程的包装器实例的访问权限,特别是封装锁定并保证您不会因使用代码中的错误而破坏共享对象的正确锁定。



给你的一个警告:不要急于说这不是我的问题,首先要彻底考虑我的解决方案。您没有准确指定问题,首先。我的解决方案是针对各种类似的问题。无论如何,欢迎您提出澄清或后续问题。



-SA
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


这篇关于在Windows服务中的线程上传递一个布尔参数化方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆