Есть функция, которая заполняет DataGridView данными. При обычном вызове этой функции программа зависает, пока функция не выполнится. Решил вызвать ее в отдельном потоке и все бы хорошо, если б не скролл в DataGridView. После выполнения потока, он "замораживается", да и во время выполнения потока, появляется по кускам как то.
Вот код функции
| Код | private: System::Void checkBids() { this->button1->Enabled = false; this->button2->Enabled = true; this->button3->Enabled = false; this->textBox1->Enabled = false; this->textBox2->Enabled = false; this->textBox3->Enabled = false; this->textBox4->Enabled = false;
this->dataGridView1->Rows->Clear();
array<double>^ bids;
for ( int i = 0; i < this->textBox1->Lines->Length; i++) { System::String^ umaxXmlUrl = L"http://xml.umaxfeed.com/xmlfeed.php?&q=" + this->textBox1->Lines[i]->Trim() + L"&aid=" + this->textBox2->Text->Trim() + L"&auth=" + this->textBox3->Text->Trim() + L"&ip=" + this->textBox4->Text->Trim();
System::Xml::XmlDocument doc; doc.Load(umaxXmlUrl);
System::Xml::XmlNodeList^ list = doc.GetElementsByTagName(L"bid"); bids = gcnew array<double>(list->Count);
for ( int j = 0; j < list->Count; j++ ) { bids[j] = System::Math::Round( System::Convert::ToDouble( list->Item(j)->InnerText->Trim()->Replace(L".", L",") ), 2); }
this->dataGridView1->Rows->Add(i+1, this->textBox1->Lines[i]->Trim(), System::Math::Round( System::Linq::Enumerable::Max(bids), 2 ), System::Math::Round( System::Linq::Enumerable::Average(bids), 2 ), System::Math::Round( System::Linq::Enumerable::Min(bids), 2 ), System::Math::Round( System::Linq::Enumerable::Sum(bids), 2) ); }
MessageBox::Show(L"Finish", L"", MessageBoxButtons::OK, MessageBoxIcon::Information);
this->button1->Enabled = true; this->button2->Enabled = false; this->button3->Enabled = true; this->textBox1->Enabled = true; this->textBox2->Enabled = true; this->textBox3->Enabled = true; this->textBox4->Enabled = true; }
|
Поток создаю так
| Код | ThreadStart^ threadDelegate = gcnew ThreadStart( this, &Form1::checkBids ); this->checkBidsThread = gcnew Thread( threadDelegate );
this->checkBidsThread->Priority = ThreadPriority::Highest; this->checkBidsThread->Start(); this->checkBidsThread->Join();
|
С многопоточностью никогда не работал, поэтому даже предположить не могу в чем может быть проблема, т.к. ошибок нет ни на этапе компиляции, ни на этапе выполнения программы. |