private void button1_Click(object sender, EventArgs e) { vk start = new vk(); if (checkBox1.Checked) // если флажон для статуса { SetStatus setStatus = new SetStatus(start.setStatus); IAsyncResult res1 = setStatus.BeginInvoke(richTextBox1.Text, null, null); res1.AsyncWaitHandle.WaitOne(2000); if (setStatus.EndInvoke(res1).IndexOf("error") != -1) { NotifyEvent ShowNotify = new NotifyEvent(ShowNotifyWindow); this.Invoke(ShowNotify, "Ошибка!", "При публикации\nвозникли проблемы!", (uint)0); } //start.setStatus(richTextBox1.Text); } else // если для записи на стене { string name = ""; if (checkBox2.Checked) // если нужно изображение, загружаем { OpenFileDialog open = new OpenFileDialog(); open.FileName = ""; open.Filter = "Изображения|*.jpg;*.gif;*.png"; if (open.ShowDialog() == DialogResult.OK) { UploadFile upload = new UploadFile(start.UploadFile); IAsyncResult res11 = upload.BeginInvoke(ID, open.FileName, null, null); int iter = 0; while (!res11.IsCompleted) { iter++; if (iter == 500) { iter = 0; Application.DoEvents(); } } res11.AsyncWaitHandle.WaitOne(); name = upload.EndInvoke(res11); } if (name == "") { NotifyEvent ShowNotify = new NotifyEvent(ShowNotifyWindow); this.Invoke(ShowNotify, "Ошибка!", "При публикации\nвозникли проблемы!", (uint)0); } } if (ID != 0) // не себе { if (name != "") { SetWallStatus setWallStatus = new SetWallStatus(start.SetWallStatus); IAsyncResult res1 = setWallStatus.BeginInvoke(richTextBox1.Text, name, ID, null, null); res1.AsyncWaitHandle.WaitOne(2000); if (setWallStatus.EndInvoke(res1).IndexOf("error") != -1) { NotifyEvent ShowNotify = new NotifyEvent(ShowNotifyWindow); this.Invoke(ShowNotify, "Ошибка!", "При публикации\nвозникли проблемы!", (uint)0); } //start.SetWallStatus(richTextBox1.Text, name, ID); } else { SetWallStatus setWallStatus = new SetWallStatus(start.SetWallStatus); IAsyncResult res1 = setWallStatus.BeginInvoke(richTextBox1.Text, "", ID, null, null); res1.AsyncWaitHandle.WaitOne(2000); if (setWallStatus.EndInvoke(res1).IndexOf("error") != -1) { NotifyEvent ShowNotify = new NotifyEvent(ShowNotifyWindow); this.Invoke(ShowNotify, "Ошибка!", "При публикации\nвозникли проблемы!", (uint)0); } //start.SetWallStatus(richTextBox1.Text, "", ID); } } else // себе { if (name != "") { SetWallStatus setWallStatus = new SetWallStatus(start.SetWallStatus); IAsyncResult res1 = setWallStatus.BeginInvoke(richTextBox1.Text, name, ID, null, null); res1.AsyncWaitHandle.WaitOne(2000); if (setWallStatus.EndInvoke(res1).IndexOf("error") != -1) { NotifyEvent ShowNotify = new NotifyEvent(ShowNotifyWindow); this.Invoke(ShowNotify, "Ошибка!", "При публикации\nвозникли проблемы!", (uint)0); } //start.SetWallStatus(richTextBox1.Text, name, ID); } else { SetStatus setWallStatus = new SetStatus(start.SetWallStatus); IAsyncResult res1 = setWallStatus.BeginInvoke(richTextBox1.Text, null, null); res1.AsyncWaitHandle.WaitOne(2000); if (setWallStatus.EndInvoke(res1).IndexOf("error") != -1) { NotifyEvent ShowNotify = new NotifyEvent(ShowNotifyWindow); this.Invoke(ShowNotify, "Ошибка!", "При публикации\nвозникли проблемы!", (uint)0); } //start.SetWallStatus(richTextBox1.Text); } } } this.Close(); }