English 中文(简体)
父线和子线是否有任何线索静态属性
原标题:Is there any ThreadStatic attribute for parent and child threads

线条和它创造的背景工人之间是否有分享价值的属性或某种方法?

我正在制作一个 SQL 服务器 CLR 组件, 它在数据库中进行搜索 + 某些计算, 我希望它是多线的。 我需要在调用线索和我创建的背景工人之间共享一些数据( 从数据库中的调用线索读到的东西, 我想传递给工人, 让他们计算我所需要的数据 ) 。

我不认为将一个类对象作为参数发送到 RunWorkerAsync 是一个好主意,因为在线条里我使用锁(项目); Interrown.Add( ref ProjectCount, -1); 机制。

我还需要的是,如果再打一个搜索电话 这两堆电话的值不会混为一谈。

谢谢!

问题回答

与其使用您想要的线索静态变量,不如考虑将通过整数作为参数,但不要将整数作为参数,而是将整数用持有者对象包起来。

class ResultHolder
{
    public int result;
}

然后,您可以使用该对象通过引用来保持您的内注。

Thread t = new Thread(Run);
var holder = new ResultHolder() { result = 0x92 }
t.Start(holder);

// Query the result
Console.WriteLine(holder.result);




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

热门标签