References in C#

  • Thread starter Thread starter Sauli V
  • Start date Start date
S

Sauli V

I've got a form code from which I call ExcelObject class to perform writing
to Excel and saving the sheet. The process is too slow and I'd like to
update my form's status bar's panel with number of records processed.
My question is since the form and ExcelObject are functionally separate
(encapsulation), how can I update status bar panel from Excel object?

C# supposedly has references but only for passing variables to methods. I
can create a string and pass it to the method by reference and if I change
the value of it inside the method, but how to tie that string to status
bar's panel's text property?

Any ideas?
 
Sauli,

You have to implement events of Excel object. Excel.Application class has
many events based on its functionality.

Set the status bar inside the event.

For example,

When you create a save a workbook, "WorkbookBeforeSave" event is fired. You
can have statusbar message there.

Shak
(Houston)
 
Sauli V said:
I've got a form code from which I call ExcelObject class to perform writing
to Excel and saving the sheet. The process is too slow and I'd like to
update my form's status bar's panel with number of records processed.
My question is since the form and ExcelObject are functionally separate
(encapsulation), how can I update status bar panel from Excel object?

C# supposedly has references but only for passing variables to methods. I
can create a string and pass it to the method by reference and if I change
the value of it inside the method, but how to tie that string to status
bar's panel's text property?

Any ideas?

Firstly, you need to get the idea of *a* reference and *by* reference
being two different things. See
http://www.pobox.com/~skeet/csharp/parameters.html

Then, what you should do is put the long-running part into a different
thread, and periodically update the status, making sure you use
Control.Invoke to "get back" to the UI thread. I would suggest creating
a public property of the form which your saving code can update, and
which calls Control.Invoke internally. You then pass a reference to
your form to the saving code, and within it you can do

form.Progress = "Starting save";

etc
 
Back
Top