0

I have a Windows Form called frmBatch.cs. It's the user interface I'm using for my project. In the code, I have a Server object (which I defined in another class).

Inside my Server object, I have a function where I add a batch to a batch server. During this process, I would like to update a status TextBox on frmBatch.cs to indicate which batch is currently being added.

How would I do this? I'm guessing I need to create a reference to the form in my Server object but I'm not sure of the best way to go about this.

gpmurthy
  • 2,397
  • 19
  • 21
arazzy
  • 495
  • 1
  • 8
  • 23
  • The following StackOverflow answer should help you... http://stackoverflow.com/questions/12131453/update-winform-controls-from-another-thread-and-class – gpmurthy Nov 01 '13 at 20:20

1 Answers1

2

There are many different ways of achieving this, but a straight forward solution is to use an event. Create an event on the server side and register your form to it. Then you can fire the event whenever the data in the form needs to be updated.

PMF
  • 14,535
  • 3
  • 23
  • 49
  • I did this and it worked but I was having a problem where I was trying to update the textbox multiple times in the same function, and it wouldn't do any of the updating until the function finished. But I fixed this by forcing a form update by using form.Update() after everytime I add text to the textbox. Thanks! – arazzy Nov 05 '13 at 17:29