public void CreateDownloadStreamAsync <T>(T data, DownloadStreamCreatedHandler <T> callBack) { DownloadStreamCreatedHandler cb = (s, e) => { var e1 = new DownloadStreamProviderEventArgs <T>((T)e.ContentSource, e.ContentMIMEType, e.DownloadFileName, e.ContentData); callBack(this, e1); }; ((IDownloadStreamProviderAsync)this).CreateDownloadStreamAsync(data, cb); }
void IDownloadStreamProviderAsync.CreateDownloadStreamAsync(object data, DownloadStreamCreatedHandler callBack) { DownloadStreamProviderEventArgs e; ManualResetEventSlim ev = new ManualResetEventSlim(); byte[] contentData = null; System.Threading.ThreadPool.QueueUserWorkItem((cb) => { contentData = ((IDownloadStreamProvider)this).CreateDownloadStream(data); ev.Set(); }); ev.Wait(); callBack(this, new DownloadStreamProviderEventArgs(data, this.ContentMIMEType, this.DownloadFileName, contentData)); }