zattz
asked on
Pass Method in Parameter
Hi,
I have never used delegates before and I am totally lost in the documentation.
Here is my code:
Basically I call DownloadAssetGroups() which calls PerformReceiveOnRepository .
However, at the end of the repository I want to call another method, on the line I've commented on that says // nextMethod(), I want to pass the nextMethod into the PerformReceiveOnRepository method
Can anybody help?
I have never used delegates before and I am totally lost in the documentation.
Here is my code:
public static void DownloadAssetGroups()
{
IBaseRepository repository = (activity.Application as AssetManagerApplication).AssetGroupRepository;
PerformReceiveOnRepository(repository);
}
private static void PerformReceiveOnRepository(IBaseRepository repository)
{
ManualResetEvent manualResetEvent = new ManualResetEvent(false);
ReceiveStatusResult statusResult = new ReceiveStatusResult();
ThreadPool.QueueUserWorkItem((s) => ReceiveClass.Receive(manualResetEvent, activity, repository, statusResult));
ThreadPool.QueueUserWorkItem((s) =>
{
manualResetEvent.WaitOne();
if (statusResult.Error) showError(statusResult);
else
{
resultToastMessage += (activity.Application as AssetManagerApplication).AssetGroupRepository.GetObjectTypeClassDisplayNamePlural() + " Downloaded " + statusResult.DownloadCount.ToString() + " New " + statusResult.NewCount.ToString() + " Modified " + statusResult.ModifiedCount.ToString() + "" + System.Environment.NewLine + System.Environment.NewLine;
//nextMethod());
}
});
}
Basically I call DownloadAssetGroups() which calls PerformReceiveOnRepository
However, at the end of the repository I want to call another method, on the line I've commented on that says // nextMethod(), I want to pass the nextMethod into the PerformReceiveOnRepository
Can anybody help?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
What's the signature for your target method? Start by making a delegate that has that same signature. Then add a parameter to your existing PerformReceiveOnRepository () method so it can receive another parameter of your new delegate type (along with any other pertinent parameters). Finally, at the end of PerformReceiveOnRepository (), simply execute your delegate (passing parameters as necessary).
ASKER
I got it to work by trial and error. I still need to take the time to understand delegates, but I was under a tight deadline. Thank you very much
ASKER