0

I've a WPF application which copy the huge volume of files from source to traget. Hence I've used dispatcher to do this job,Eventhough my application has freezed and saying "Not Responding" in the title bar until file copy complete.

ButtonPower.Dispatcher.BeginInvoke(
System.Windows.Threading.DispatcherPriority.Send,
new NextPrimeDelegate(this.DoAction));  

I'd like to show the progress bar until the copying operation complete also the window shouldn't freezed. I'd apprciate any solution or suggestion to solve this

Smaug
  • 2,625
  • 5
  • 28
  • 44

2 Answers2

4

Using the Dispatcher does not mean your UI will not freeze - in fact the dispatcher ensures that all work is done on the same UI thread and thus you will freeze the UI. Instead you should spawn off a new thread and perform the work there. Then use the dispatcher to notify the UI of updates, because this is not allowed from within the new thread. That's what the dispatcher is mainly for!

See this answer for a good implementation and further ideas.

Community
  • 1
  • 1
Sebastian
  • 7,729
  • 2
  • 37
  • 69
  • I totally agree with you, but i dont know how to implement new thread? can you give me example or the reference link ? – Smaug Mar 09 '13 at 12:39
0

You can use DisableProcessWindowsGhosting as follows

[DllImport("user32.dll")]
public static extern void DisableProcessWindowsGhosting();
Pranav Singh
  • 17,079
  • 30
  • 77
  • 104
Ajay
  • 1
  • So this is the P-Invoke declaration. Where would you call it? At the launching of the application? – XouDo Jun 10 '21 at 12:41