private void btnCreateNetwork_Click(object sender, EventArgs e) { btnCreateNetwork.Enabled = false; UpdateControlStatus(btnCreateNetwork); if (mMnistLoader == null) { lblDataLoaded.Text = "Loading data..."; UpdateControlStatus(lblDataLoaded); LoadData(); } lblDataLoaded.Text = "Data loaded, training network..."; UpdateControlStatus(lblDataLoaded); CleanUpOldNetwork(); mNetwork = CreateNetwork(); Task.Factory.StartNew(() => mNetwork.SGD( mMnistLoader.TrainingData, (int)nudEpochs.Value, (int)nudBatchSize.Value, (float)nudLearningRate.Value, mMnistLoader.TestData) ) .ContinueWith(t => { btnCreateNetwork.Enabled = true; lblDataLoaded.Text = "Training Finished!"; } , TaskScheduler.FromCurrentSynchronizationContext()); }