0
我在Visual Studio 2015中創建了C#Windows窗體應用程序。應用程序計算一些數據,然後將其分配給預定義的int變量並在輸出中顯示它們安慰。C#WPF應用程序在調試模式下掛起,在VS 2015斷點模式下完美工作
問題是應用程序正在經歷所有代碼,沒有錯誤的斷點模式,直到整個代碼的結尾,並給我在控制檯輸出,我想要的。但是,如果我通過調試模式(F5)運行程序,甚至沒有調試模式(Ctrl + F5),那麼我沒有輸出和程序掛起。經過一段時間後,它拋出ContentDeadlockException。
感謝您的答案。
編輯:
好了,這裏是我的應用程序的未完成的GUI:picture 當我點擊「運行算法」按鈕,程序在調試模式下掛起。如果我嘗試在斷點模式下進行調試,那麼在聲明之後運行聲明它是正確的。
還有就是我的這種形式的代碼:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication3
{
public partial class IterationAlgorithm : Form
{
//Random random;
List<IZadPrac> workersList = new List<IZadPrac>();
List<IZadPrac> jobsList = new List<IZadPrac>();
public bool[,] generateTable(bool[,] tableGiven)
{
bool isRight = false;
while (!isRight)
{
Array.Clear(tableGiven, 0, tableGiven.Length);
for (int i = 0; i < tableGiven.GetLength(0); i++)
{
Random random = new Random();
tableGiven[i, random.Next(tableGiven.GetLength(1))] = true;
}
int jobsTimeSum;
for (int i = 0; i < workersList.Count; i++)
{
jobsTimeSum = 0;
for (int j = 0; j < jobsList.Count; j++)
{
if (tableGiven[j, i]) jobsTimeSum += jobsList[j].showJobTime();
if (workersList[i].showWorkerTime() < jobsTimeSum)
{
j = jobsList.Count;
i = workersList.Count;
isRight = false;
}
else
{
isRight = true;
}
}
}
}
return tableGiven;
}
public int FindFunctionMin(bool[,] tableGiven)
{
int goalFunction = 0;
for(int i = 0; i < jobsList.Count; i ++)
{
for(int j = 0; j < workersList.Count; j++)
{
if (tableGiven[i, j])
{
goalFunction += workersList[j].showCompetitions()[i] * jobsList[i].showJobTime();
j = workersList.Count;
}
}
}
return goalFunction;
}
public IterationAlgorithm(List<IZadPrac> ListaPrac, List<IZadPrac> ListaZad)
{
InitializeComponent();
this.workersList = ListaPrac;
this.jobsList = ListaZad;
bool[,] boolTable = new bool[jobsList.Count, workersList.Count];
Array.Clear(boolTable, 0, boolTable.Length);
//List<bool[,]> listOfTables = new List<bool[,]>();
//int counter = 0;
//int goalFunctionTemp = 0;
List<int> funkcjaCelu = new List<int>();
List<IZadPrac> workListCopy = new List<IZadPrac>();
List<IZadPrac> jobListCopy = new List<IZadPrac>();
int goalFunctionTemp = 999999;
workListCopy = jobsList;
jobListCopy = workersList;
}
private void button1_Click(object sender, EventArgs e)
{
bool[,] booltable = new bool[jobsList.Count, workersList.Count];
Array.Clear(booltable, 0, booltable.Length);
int counter = 0;
int max;
int functionmin = 999999;
bool error = false;
List<int> funkcjaCelu = new List<int>();
if(textBox1.Text != String.Empty)
{
max = Int32.Parse(textBox1.Text);
while (counter < max)
{
int number = FindFunctionMin(generateTable(booltable));
if (functionmin > number) functionmin = number;
counter++;
}
label2.Text = "The smallest value of function " + functionmin.ToString();
}
}
}
}
當我在暫停按鈕按在調試模式下,則breapoint爲「GenerateTable」功能。
感謝您的答案。
給我們一些代碼。就像在這個時候在黑暗中拍攝一樣。從我看到的你的應用程序中的競爭條件與並行線程 – Karolis