private async void RunButton_Clicked(object sender, EventArgs e)
{
progressBar.Progress = 0.0;
if(!IsAppRunning)
{
IsAppRunning = true;
RunButton.Text = "Cancel";
RunButton.TextColor = Colors.White;
RunButton.Background = Colors.Red;
m_cancelTokenSource = new CancellationTokenSource();
try
{
if (!DEBUG)
if (actionOperator == "mul")
if (CheckIsThisASpatialMul())
await alfaStarsSpatialMul(m_cancelTokenSource.Token);
else
await alfaStarsMul(m_cancelTokenSource.Token);
else if (actionOperator == "div0")
await alfaStarsSpatialDiv(m_cancelTokenSource.Token);
else if (actionOperator == "div1")
await alfaStarsDiv1(m_cancelTokenSource.Token);
else if (actionOperator == "div2")
await alfaStarsDiv2(m_cancelTokenSource.Token);
else if (actionOperator == "div3")
await alfaStarsDiv3(m_cancelTokenSource.Token);
else if (actionOperator == "div4")
await alfaStarsDiv4(m_cancelTokenSource.Token);
else if (actionOperator == "addsub")
await alfaStarsAdSb(m_cancelTokenSource.Token);
else if (actionOperator == "add")
await alfaStarsAdd(m_cancelTokenSource.Token);
else if (actionOperator == "sub")
await alfaStarsSub(m_cancelTokenSource.Token);
else if (actionOperator == "sqr")
await alfaStarsSqr(m_cancelTokenSource.Token);
else
{
//thisMsg = "Wrong Input : \r\n";
}
endif
if (DEBUG)
if (actionOperator == "mul")
if (CheckIsThisASpatialMul())
alfaStarsSpatialMul();
else
alfaStarsMul();
else if (actionOperator == "div0")
alfaStarsSpatialDiv();
else if (actionOperator == "div1")
alfaStarsDiv1();
else if (actionOperator == "div2")
alfaStarsDiv2();
else if (actionOperator == "div3")
alfaStarsDiv3();
else if (actionOperator == "div4")
alfaStarsDiv4();
else if (actionOperator == "addsub")
alfaStarsAdSb();
else if (actionOperator == "add")
alfaStarsAdd();
else if (actionOperator == "sub")
alfaStarsSub();
else if (actionOperator == "sqr")
alfaStarsSqr();
else
{
//thisMsg = "Wrong Input : \r\n";
}
endif
}
catch (OperationCanceledException)
{
//
}
finally
{
RunButton.Text = "Start";
RunButton.TextColor = Colors.White;
RunButton.Background = Microsoft.Maui.Graphics.Color.FromArgb("512BD4");
IsAppRunning = false;
m_cancelTokenSource = null;
progressBar.Progress = 0.0;
}
}
else
{
m_cancelTokenSource.Cancel();
}
return;
}
//-----------------------------------------------------------------------------
if (DEBUG)
public void alfaStarsSpatialMul()
{
endif
if (!DEBUG)
public Task alfaStarsSpatialMul(CancellationToken ct)
{
return Task.Run(() =>
{
endif
try
{
int cnt;
int starsQty = 0;
int i;
ulong loopsCnt = 0;
for(combs = 0; combs < combsCnt; combs++)
{
if (!DEBUG)
progValue = (double)combs / (double)combsCnt;
MainThread.BeginInvokeOnMainThread(() => { progressBar.Progress = progValue; });
endif
iPN = 1;
while (iPN < PN)
{
iPY = 0;
while(iPY < PY)//*** while(iPY < PY) Algorithm section ******************
{
if (!DEBUG)
if (ct.IsCancellationRequested)
{
stopwatch.Stop();
strOutputTBText += $"\r\nCanceled at Loop {loopsCnt}";
strOutputTBText += "\r\n";
strOutputTBText += "Time elapsed:\r\n" + stopwatch.Elapsed;
strOutputTBText += "\r\n";
MainThread.BeginInvokeOnMainThread(() => {OutputTB.Text += strOutputTBText;});
if (fromToCKB.IsChecked == false) IsFromToSetToZero = false;
if(alphaCKB.IsChecked == false) IsAlphaMode = false;
throw new OperationCanceledException(ct);
}
endif
}// while(iPY < PY)
}// while (iPN < PN)
}//for(combs
strOutputTBText += $"\r\n {loopsCnt} Loops";
strOutputTBText += "\r\n";
stopwatch.Stop();
strOutputTBText += "Time elapsed:\r\n" + stopwatch.Elapsed;
strOutputTBText += "\r\n";
MainThread.BeginInvokeOnMainThread(() => {OutputTB.Text += strOutputTBText;});
NoSolution();
}
catch (Exception ex)
{
if(ex.ToString().Contains("OperationCanceledException"))
{
//
}
else
{
strOutputTBText += "\r\n\r\n";
strOutputTBText += $"Exception = " + ex + "\r\n";
strOutputTBText += $"Invalid Puzzle";
strOutputTBText += "\r\n\r\n";
MainThread.BeginInvokeOnMainThread(() => {OutputTB.Text += strOutputTBText;});
}
}
finally
{
if (fromToCKB.IsChecked == false) IsFromToSetToZero = false;
if(alphaCKB.IsChecked == false) IsAlphaMode = false;
progressBar.Progress = 0.0;
}
if (!DEBUG)
}, ct);
endif
}//alfaStarsSpatialMul()