Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy is Visual Studio 2010 telling me "'System.Delegate' does not contain a definition for 'EndInvoke'"?
    text
    copied!<p>Why is Visual Studio 2010 telling me "'System.Delegate' does not contain a definition for 'EndInvoke'" when I call <code>job.Delegate.EndInvoke()</code>? How do I fix it? Note that it likes <code>BeginInvoke()</code> just fine, and doesn't complain if I add <code>EndInvoke()</code> immediately after <code>BeginInvoke()</code> (thought hat doesn't accomplish what I want).</p> <p>I have a little JobTracker class for tracking backup jobs:</p> <pre><code>public class JobTracker { private class Job { public Account Account { get; set; } public IAsyncResult Result { get; set; } public Delegate Delegate { get; set; } public bool IsCompleted { get { return result.IsCompleted } } public string Instance { get { return Account.Instance } } } public List&lt;Job&gt; Running = new List&lt;Job&gt;; public void AddJob(Account a, IAsyncResult result, Delegate del) { var j = new Job { Account = a, Result = result, Delegate = del }; Running.Add(j); } public void RemoveJob(Job job) { Running.Remove(job); } public bool IsInstanceRunning(string instance) { return (Running.Count(x =&gt; x.Instance == instance) &gt; 0); } } </code></pre> <p>These backup jobs will happen asynchronously via BeginInvoke()/EndInvoke(). The calling code (simplified) looks something like this:</p> <pre><code>public void BackupAccounts(IEnumerable&lt;Account&gt; accounts, int maxconcurrent = 4) { // local copy List&lt;Accounts&gt; myaccounts = accounts.ToList(); var jobs = new JobTracker(); while (myaccounts.Count &gt; 0) { // check our running jobs foreach (var job in jobs.Running) { if (job.IsCompleted) { // PROBLEM LINE: job.Delegate.EndInvoke(); jobs.RemoveJob(job); } } // more jobs! while (jobs.Count &lt; maxconcurrent) { int i = 0; Account account = null; // choose the next account on a free instance while (int &lt; accounts.Count) { account = accounts[i]; // instance in use? if (jobs.InstanceIsRunning(account.Instance)) { i += 1; continue; } else { // start the job accounts.RemoveAt(i); BackupDelegate del = new BackupDelegate(BackupAccount, account); IAsyncResult result = del.BeginInvoke(); jobs.AddJob(account, result, del); } } } // we're all full up, give it some time to work Thread.Sleep(2000); } } </code></pre> <p>PS - I know this code can be greatly simplified. It's a first, get-it-working iteration -- I just can't figure out why VS doesn't like it. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload