【问题标题】:Calling a function from the main thread and making it working in parallel with a function in the main thread (part 2)从主线程调用函数并使其与主线程中的函数并行工作(第 2 部分)
【发布时间】:2008-12-04 08:25:41
【问题描述】:

谢谢你所有的重播.. 我试过你的选择,我想问一下这是否正确,这两个线程是否并行工作..

这是我的代码:

//在Form.Load()中

        Timer1.Enabled = true;
        Timer1.Start();

        if (InvokeRequired)
        {
            Invoke(new GetFromServerHandler(GetFromServer));
            Invoke(new GetFromPCHandler(GetFromPC));
        }
        else
        {
            ServerQuranTreeView.Nodes.Clear();
            GetFromServer();
            GetFromPC();
        }

//另外2个函数,分别是delegate和函数(GetFromServer)和(GetFromPC)

    private delegate void GetFromServerHandler(); 
    private void GetFromServer()
    {
    }

    private delegate void GetFromPCHandler(); 
    private void GetFromPC()
    {
    }

// 现在应用程序需要几秒钟才能启动(我解释说它需要这个时间才能从服务器获取数据)

是这样吗,还是我错过了什么?

请提前

【问题讨论】:

  • 34 个问题,几乎没有公认的答案.... hrmmmm.

标签: c# .net multithreading


【解决方案1】:

我真的不明白你在这里要做什么:S 请澄清。至少我可以说你通常不需要在 Form_Load 处理程序中调用。

你真的必须修复你的帖子的标签,它们应该描述你的问题,即:像 c# threading invoke 这样的东西。

您必须帮助我们帮助您。顺便说一句,如果您已经就该主题提出过问题,您至少可以包含指向该问题的链接。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-01-05
    • 1970-01-01
    • 2022-10-15
    • 2011-10-24
    • 1970-01-01
    • 1970-01-01
    • 2012-11-20
    相关资源
    最近更新 更多