English 中文(简体)
• 采用单一州多读C#方案
原标题:Making a program with singletons multithreaded C#

我在C#中写过了一个方案。 现在,我完成了所有功能,并发挥了作用。 但只有一对一线。 我做大量计算,有时在申请中装上大约300份甲基溴或更多测量文档。

我现在想使该方案变得多面,因为在密集处理或i/o作业时,用户的权宜之计确实很差。

What is the best way to refactor the program, so that it can be made multithreaded without too much affort? I know this is stuff I should have thougth before. But I havn t.

我使用了单一吨模式,用于大约3个重要单元,这些单元几乎涉及该方案的所有其他功能。

I used a more or less clean MVC (Model View Control) architecture. So I wonder if it is maybe possible to let the User Interface run in one thread and the rest of the application in another.

If not, loading and parsing 300MB, creating objects will take about 3 minutes to finish. In this time the user gets no response from the GUI. :/

UPDATE: My singletons are used as a kind of storage. One singleton saves the objects of the parsed measurement files, while the other singleton saves the result. I have different calculations, which use the same measurementfiles and creating results which they want to save using the other singleton. This is one problem.

第二是保持对用户行动的伪装,或至少避免这一警告,即窗口没有作出反应。

感谢大家的所有建议。 我将审判他们。 晚期答复。

最佳回答

最容易的方法是将所有计算转换成一个单独的校对,并使用<条码>Invoke/<条码>更新《全球倡议》。

public partial class MyForm : Form
{
    Thread _workerThread;

    public MyForm()
    {
        _workerThread = new Thread(Calculate);
    }

    public void StartCalc()
    {
        _workerThread.Start();
    }

    public void Calculate()
    {
        //call singleton here


    }

    // true if user are allowed to change calc settings
    public bool CanUpdateSettings
    {
        get { return !_workerThread.IsAlive; } }
    }
}

这样,在计算工作进行期间,你就得到了全球倡议的答复。

只要你不允许用户在进行计算时作出改动,申请就会安全。

利用几条镜子进行计算,是一个更加复杂的故事,我们需要更多的信息,才能给你适当的答案。

问题回答

总的来说,我避免了单一州的模式,因为它在道路上造成了许多问题,特别是在测试方面。 然而,如果你想要的是一只一顿一线一线一线,那么就有一个非常简单的解决办法,使这项工作达到多面。 • 指定你在某个领域(而不是一个财产)的单一吨位,并与ThreadStaticAttribute:

public class MySingleton
{
   [ThreadStatic]
   private static MySingletonClass _instance = new MySingletonClass();
   public static MySingletonClass Instance { get { return _instance; } }
}

现在,每一条路边都有自己的美术。

您可使用http://msdn.microsoft.com/en-us/library/d460717.aspx” rel=“nofollow”>TPL

你们能够使地方住房单元与地方住房单元平行,并且更进一步地与地方住房融为一体。 NET 4.0,以便你不必改变你的方案





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签