1

I have this code

    private void button1_Click(object sender, EventArgs e)
    {
        //===========> Getting error here <==================//
        textBox2.Text = CallFunc(textBox1.Text);
    }

    static async Task<string> CallFunc(string str)
    {
        Program p = new Program();
        string s = await p.DocumentToText(str);
        return s;
    }


public async Task<string> DocumentToText(string path)
    {
        string txt = String.Empty;
        AmazonTextractClient client = new AmazonTextractClient(key, Skey, reg);
        //some AWS functionality

        Thread.Sleep(2000);
        txt = "hello world";
        return txt;
     }

I changed this button1_Click function to

    private void button1_Click(object sender, EventArgs e)
    {
        var d = await CallFunc(textBox1.Text);
        textBox2.Text = d.Results();
    }

as was recommended by one answers of this question

Cannot implicitly convert type 'string' to 'System.Threading.Tasks.Task<string>'

but that still does not work

enter image description here

1
  • Do not use Thread.Sleep in an async method. Use await Task.Delay instead. Commented Dec 25, 2021 at 13:06

2 Answers 2

6

Add async in button1_Click event

private async void button1_Click(object sender, EventArgs e)
{
    var d = await CallFunc(textBox1.Text);
    textBox2.Text = d;
}
Sign up to request clarification or add additional context in comments.

2 Comments

error : string does not contain definition from "Result"
Use textBox2.Text = d;
1

Use Async Task in button1_Click method

private async Task button1_Click(object sender, EventArgs e)
{
    var d = await CallFunc(textBox1.Text);
    textBox2.Text = d.Results();
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.