I've been reading some code about Data Virtualization on the internet. I met with a function called BeginInvoke. Basically, I know what it is used for. But this function has a version with three parameters which I didn't look up in MSDN.
I did find it in MSDN which has two parameters at most:
Also I don't think this is the one I want:
Because the three-parameters version has a DispatcherPriority type for its first parameter which the code I read doesn't pass.
The code I'm reading is:
using System;
using System.Threading;
namespace WPF.DataVirtualization
{
public class AsyncDataRef<TId, T> : DataRefBase<T> where T : class
{
private readonly TId m_Id;
private int m_Loading;
private readonly Func<TId, T> Load;
private volatile T m_Data;
public AsyncDataRef(TId id, Func<TId, T> load)
{
m_Id = id;
Load = load;
}
public override T Data
{
get
{
if (m_Data != null)
return m_Data;
if (Interlocked.Increment(ref m_Loading) == 1)
if (m_Data == null)
Load.BeginInvoke(m_Id, AsyncLoadCallback, null);
else
Interlocked.Decrement(ref m_Loading);
else
Interlocked.Decrement(ref m_Loading);
return m_Data;
}
}
private void AsyncLoadCallback(IAsyncResult ar)
{
m_Data = Load.EndInvoke(ar);
Interlocked.Decrement(ref m_Loading);
// when the object is loaded, signal that all the properties have changed
NotifyAllPropertiesChanged();
}
}
}
And when call this function, it uses it like this:
var list = new List<DataRefBase<Person>>(itemCount);
...
list.Add(new AsyncDataRef<int, Person>(i, LoadPerson));
Person is another kind of class. LoadPerson is a delegate function. DataRefBase is a kind of template class.
My question is this line:
Load.BeginInvoke(m_Id, AsyncLoadCallback, null);
What do the three parameters do? (It seems that m_Id is used as an int)What do they stand for? Where can I find the document of this version of BeginInvoke.