|
-
Jan 24th, 2010, 10:16 PM
#1
Thread Starter
Hyperactive Member
Memory Leaks
Memory Management is know issue while using WPF, but I've read workarounds for this problems.
In my case I'm struggling with Events, I want to make sure the following piece of code is creating, and eliminating the event handlers.
I'm creating and using a BackgroundWorker to perform some actions.
Here's the code, I'll place the explanation after it.
csharp Code:
//I'm using Static Void because It is contained within a static class
//I'm creating a background worker for each void call
public static void LoadData()
{
BackgroundWorker data_worker = new BackgroundWorker();
data_worker.DoWork += new DoWorkEventHandler(data_worker_DoWork);
data_worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(data_worker_RunWorkerCompleted);
data_worker.WorkerReportsProgress = true;
data_worker.ProgressChanged += new ProgressChangedEventHandler(data_worker_ProgressChanged);
data_worker.RunWorkerAsync();
}
//Background Worker events
//**DoWork
static void data_worker_DoWork(object sender, DoWorkEventArgs e)
{
//Perform Work
}
//**Completed
static void data_worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
// Should Clear Event Handlers ?
// ((BackgroundWorker)sender).DoWork -= new
// DoWorkEventHandler(data_worker_DoWork); ?
//Work Completed
}
Is this code creating the background worker in a way it will be destroyed after it's work has been performed ? If not what should I do to make it so.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|