English 中文(简体)
如何从C#的深处获得非静态方法
原标题:How to access a non-static method from a thread in C#

我不敢肯定,如果这是好的方案拟订和分类,那么我就有一个正常的方法,即更新某些数据和数据参数,如文字锁等。

不管怎么说,我想制造一个线索,即每X分之一使用更新方法,但我不能使用,因为从我理解的透镜只能使用静态方法。

这方面的最佳途径是什么?

感谢

毫克。

最佳回答

从我所理解的表面来看,只能采用静态方法。

这根本不是事实。 你们可以开始这样的read子:

Thread thread = new Thread(() => { foo.bar(123, 456); });
thread.Start();

方法条码不一定是静态的,但你确实需要提及能够称作一种实例方法的物体。

如果你采用无参数的方法,你也可以这样做:

Thread thread = new Thread(bar);

你们应该指出,你不能从主线以外的另一面修改《全球倡议》,这样,如果你们想要做的是更新《全球倡议》的话,你就不开始新的路面。 如果你有很长的运行过程,并想偶尔更新《全球倡议》,以显示进展,同时又不阻碍《国际倡议》,你可访问。 背景工作人

或者,你可以利用Invoke模式,从背景阅读中更新全球倡议:

private void updateFoo()
{
    if (InvokeRequired)
    {
        Invoke(new MethodInvoker(() => { updateFoo(); }));
    }
    else
    {
        // Do the update.
    }
}

见这一相关问题:。 C#: 自动配对因沃克要求代码格式

问题回答




相关问题
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. ...

热门标签