You're not trying to call a console application from a Windows Forms application; you're trying to call a method in one class from another class.
Since the method you're trying to call is
static
, you just need to put the name of the containing class before it.
Since the method you're trying to call is
async
, you'll need an
async
method to call it if you want to use the results. But you should
avoid async void
methods[
^] wherever possible.
Update your
MakePredictionRequest
method to return the value you want to use:
public static async Task<object> MakePredictionRequest(string imageFilePath)
{
...
string responseString = await response.Content.ReadAsStringAsync();
return JsonConvert.DeserializeObject<object>(responseString);
}
}
Then update your form code to call it and use the result:
private void button1_Click(object sender, EventArgs e)
{
openFD.InitialDirectory = "C:";
openFD.Title = "Submit an Image";
openFD.FileName = "";
openFD.Filter = "JPEG Images|*.jpg|GIF Images|*.gif";
if (openFD.ShowDialog() == DialogResult.Cancel)
{
MessageBox.Show("Operation Cancelled");
return;
}
string Chosen_File = openFD.FileName;
pictureBox1.Image = Image.FromFile(Chosen_File);
string imageFilePath = Path.GetDirectoryName(Chosen_File);
_ = Predict(Chosen_File);
}
private async Task Predict(string imageFilePath)
{
dynamic stuff = await Program.MakePredictionRequest(imageFilePath);
string broken = stuff.predictions[0].probability;
string negative = stuff.predictions[1].probability;
...
}