我有一个类ReceiveFaxPrintHelper在c#中,我实现为密封。我也实现了这个作为Singleton。我在这个类中定义了一个方法PrintStoredFaxes,我使用锁来保护它。正在使用c#中的多线程安全结构#
我有的问题是,如果我改变ReceiveFaxPrintHelper从类到结构,这是否会影响我的线程? Ndepend建议我将其改为结构而不是类。
public sealed class ReceiveFaxPrintHelper
{
private static AutoResetEvent mJobCompleted = new AutoResetEvent(false);
private bool mPrintStoredFaxesInProgress = false;
private object mLockPrint = new object();
private const string mClassName = "ReceiveFaxPrintHelper";
/// <summary>
/// Function that prints the Stored Faxes
/// </summary>
/// <param name="o">completing the delegate message signature</param>
public void PrintStoredFaxes(object o)
{
lock (mLockPrint)
{
我用这个像这样:
ThreadPool.QueueUserWorkItem(new WaitCallback(ReceiveFaxPrintHelper.Instance.PrintStoredFaxes));
你知道的结构和类之间的区别?因为基于这个问题,它不会像你这样做,你可能想对这个问题做一些研究。如果你想要一个你的对象的实例,你应该使用一个类而不是结构。 –
接受至少80%的问题让人们开始回答你。 – AgentFire