Krzysiek
Krzysiek

Reputation: 1527

Problems with refreshing a form

I have a form with labels A, B and C. In static void Main(), I say:

Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Form1 form1 = new Form1();
Application.Run(form1);

Form1 constructor calls

InitializeComponent();
updateForm();

where updateForm reads a log ((FtpWebRequest)WebRequest) from a remote machine and updates the labels appropriately.

I would like to constantly update the form, because the remote log file is changing every few minutes.

I tried calling form1.updateLog() in while(true) loop in the main method, but the form doesn't refresh. Also, form1.Refresh() doesn't seem to work.

Any hints? Thanks.

Upvotes: 0

Views: 62

Answers (1)

Joey
Joey

Reputation: 354356

When you're doing that in a loop then most likely on the UI thread. This means that you constantly tell the Form to repaint yet don't give it time or an opportunity to do so (remember: you're blocking the thread on which it would do that).

Instead use a timer and refresh from there, e.g. every 100 ms or so.

Upvotes: 1

Related Questions