private void MainWork(object parameter) { string imageUrl = ""; try { string url = "http://www.imageshack.us/upload_api.php?"; MemoryStream ms = new MemoryStream(); CurrentScreenShot.Save(ms, ImageFormat.Jpeg); ms.Position = 0; OnUploadingStep(); string data = "public&key=2BJMPTXYf1a3a7292a65c957a26c1e8f088ecc18"; string result = UploadManager.UploadFile(ms, url, "fileupload", "image/jpeg", data); XmlDocument doc = new XmlDocument(); doc.LoadXml(result); OnUploadingStep(); XmlNodeList resultNodes = doc.GetElementsByTagName("links"); if (resultNodes.Count > 0) { XmlNode linkNode = resultNodes[0]; int value = OnDataReceived(linkNode.ChildNodes.Count); if (linkNode.ChildNodes.Count > 0) imageUrl = linkNode.ChildNodes[0].InnerText; foreach (XmlElement item in linkNode.ChildNodes) { DataControl dc = new DataControl(item); OnUploadingStep(value, dc); } } } catch (ThreadStateException) { } catch (ThreadAbortException) { } OnUploadingComplete(parameter, imageUrl); }
public UploadingStepEventArgs(int value, DataControl control) : this(value) { this.DataControl = control; }
public void OnUploadingStep(int value = 0, DataControl control = null) { if (UploadingStep != null) UploadingStep(this, new UploadingStepEventArgs(value, control)); }