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