I'm just messing around with my first wpf app, and one of the things I've implemented is an insertion sort. I have the sort Method running ASync to the rest of the app, as to not freeze up the rest of the app. I am trying to implement a progress bar to show how far through the sort the computer is, but with no luck.
So I'm guessing that it doesn't like calling an item in another core, am I right? How do I fix this, and make the progress bar work?
Below is the code
Thanks!
InsertionSort Method:
private int[] performInsertionSort(int[] inputarray)
{
for (int i = 0; i < inputarray.Length - 1; i++)
{
int j = i + 1;
while (j > 0)
{
if (inputarray[j - 1] > inputarray[j])
{
int temp = inputarray[j - 1];
inputarray[j - 1] = inputarray[j];
inputarray[j] = temp;
}
j--;
int RealJ = inputarray.Length - j;
ProgB.Value = inputarray.Length / RealJ * 100;
}
}
return inputarray;
}
The event handler of the button that starts the InsertionSort Method:
private void button_Click(object sender, RoutedEventArgs e)
{
int SInt;
if (Int32.TryParse(textBox0.Text, out SInt))
Console.WriteLine(SInt);
else
Console.WriteLine("S String could not be parsed.");
int[] SortList = new int[SInt];
Random randNum = new Random();
foreach (int value in SortList)
{
randNum.Next(0, 999999);
}
new Task(() => { performInsertionSort(SortList); }).Start();
//performInsertionSort(SortList);
}