If this is interactive, this is one thing. You don't need much, and the solution by Edward would be a complete answer.
However, if you are developing an algorithm actually solving the problem, and if you want to visualize the step (or even if not but if the solution takes some noticeable time which is very likely), the problem is not that you need to send notification "without exiting such function". The problem will look completely different: you will need to run the solution is a separate thread. And then the problem of giving notification to the UI thread looks not so trivial. The right mechanism is the one of UI thread delegate
invocation.
You cannot call anything related to UI from non-UI thread. Instead, you need to use the method
Invoke
or
BeginInvoke
of
System.Windows.Threading.Dispatcher
(for both Forms or WPF) or
System.Windows.Forms.Control
(Forms only).
You will find detailed explanation of how it works and code samples in my past answers:
Control.Invoke() vs. Control.BeginInvoke()[
^],
Problem with Treeview Scanner And MD5[
^].
See also more references on threading:
How to get a keydown event to operate on a different thread in vb.net[
^],
Control events not firing after enable disable + multithreading[
^].
—SA