Solved

Why does this code for a worker thread not work?

Posted on 2008-09-29
4
349 Views
Last Modified: 2013-12-17
I have a windows form that writes a large text file to the hard disk, because of the size of the file the operation takes a long time and the user's work is disrupted.  I need to start a worker thread for this process to run in but I also would like to update the record count on the page regularly through the UI thread for a progress incicator.

I don't understand why the following code is not working.  I get a compilation error "The type or namespace name 'RecordDisplayEvents' could not be found (are you missing a using directive or an assembly reference?)" on line 330 and 332.
13 public partial class frmMain : Form
14     {
 ...
 
313        public void ShowRecCount(string msg, int recordsDone)
314        {
315            // ###########################################################
316            // Wrap the parameters in an EventArgs-derived custom class:
317            // ###########################################################
318
319            System.EventArgs e = new RecordDisplayEvents(msg, recordsDone);
320            object[] pList = { this, e };
321
322            // ###########################################################
323            // Invoke the method. This class is derived from Form,
324            // so we can just call BeginInvoke to get to the UI thread.
325            // ###########################################################
326
327            BeginInvoke(new RecordDisplayEventsHandler(UpdateUI), pList);
328        }
329
330        private delegate void RecordDisplayEventsHandler(object sender, RecordDisplayEvents e);
331
332        private void UpdateUI(object sender, RecordDisplayEvents e)
333        {
334            txtError.Text = e.Msg;
335            txtRecCount.Text = e.recordsDone.toString();
336        }
337    }

Open in new window

0
Comment
Question by:mdcadu
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 

Expert Comment

by:naik_sanket
ID: 22596297
Did you try modifyung the access modifier of the delegate to public ? Or is it that you do not want to do that ?
0
 
LVL 4

Accepted Solution

by:
Makolyte earned 250 total points
ID: 22596755
Where is the class "RecordDisplayEvents" defined?
0
 
LVL 37

Expert Comment

by:gregoryyoung
ID: 22598303
Makolyte has it right ... you actually have to define that class somewhere.
0
 

Author Closing Comment

by:mdcadu
ID: 31501177
This suggestion pointed me to where I was able to find the problem.
0

Featured Post

Why You Need a DevOps Toolchain

IT needs to deliver services with more agility and velocity. IT must roll out application features and innovations faster to keep up with customer demands, which is where a DevOps toolchain steps in. View the infographic to see why you need a DevOps toolchain.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Visual Studio npm 1 39
orderby list (from Json) 1 44
PowerShell:  Use of subproperties in a Select statement 7 69
AD Computer Objects in VB .Net 2 17
A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question