C# Update UI In Task
<p>I am new to <code>C#</code> <code>Task</code> and threading. </p>

<p>I have a code like below:- </p>

<pre><code>public void UpdateSales(object sender, EventArgs args)
{
    Task.Run(() =&gt;
    {
    // Some code Create Collection ...
    // Some code with business logic  ..


    // Below code is to update UI
    // is it safe to update UI like below 

       saleDataGrid.Dispatcher.Invoke((Action) (() =&gt;
                                {

                                    saleDataGrid.ItemsSource = currentCollection;
                                    saleDataGrid.Items.Refresh();
                                })); 

    });
}
</code></pre>

<p>I am not sure if this code is correct or not. I am think in any case deadlock can occur? </p>

<p>Can you please point how can i update UI from Task? i am not using <code>async/await</code>  because <code>UpdateSales</code> is event handler from third party library. </p>