English 中文(简体)
在利用BeginInvoke进行多读时如何锁定资源?
原标题:How to lock resource when using BeginInvoke for multithreading?

我有一种方法,对属于某个用户的一些数据进行分类,将其节省到数据库。

delegate void parseUserDataDelegate(string pathToFile);

我为此设立了一个代表,并与BeginInvoke一起进行平行处理。

parseUserDataDelegate deleg = new parseUserData(this.parseUserData);
IAsyncResult result = deleg.BeginInvoke(path, null, null);
deleg.EndInvoke(result);

问题是,有两张表格:一是外国钥匙使用的数据,另一张是用户表格。 如果在分配方法时没有相应的用户,则在用户表中增加一个新的条目,并使用其补贴。 一个用户的数据表中约有100个条目。 问题在于,当处理第一用户的所有数据时,会发现一个错误,因为两条镜子试图为第二用户制造同样的条目。 我如何为不同的深层打开用户台?

问题回答

根据你的法典。 我建议,寻找用户和选择性地创造新用户的方法,在什么地方被束缚。

lock(NewUserSync)
{
  FooBar();
}

新UserSync是这些工人的read子共有的平原。 如果教区法是班级的,则由校长创建(这种方法在多个校方开始之前)。 用户识别器当然可以在一些共同物体(随时需要安全)中贴出。





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

热门标签