how to cancel a function after a while?
<p>I want to know how can I cancel a function after a certain time!</p>

<p>for example, how can I cancel this function?</p>

<pre><code>private async Task function()
    {
        try
        {
            while (true)
            {
                //mycode
            }
        }
        catch{ }
    }
</code></pre>