Form will not show

C

Cub71

I have a small app with a mainForm taking some info from comboboxes
and textboxes. These data are sendt with HttpWebRequest.

What I now have problems with is to show a "Please Wait" message while
it is sending. I have tried several approaches to this but none of
these work. It seems like the code is so eager with sending the data
that it forgets to paint the new message. :-|


private void menuItemSend_Click(object sender, EventArgs e)
{
String message = textBoxFreeText.Text;

PleaseWaitForm pwf = new PleaseWaitForm(message);
pwf.ShowDialog();
}

In the PleaseWaitForm I have this:

private void PleaseWaitForm_Load(object sender, EventArgs e)
{

ThreadStart starter = new ThreadStart(this.SendData);
Thread t = new Thread(starter);
t.Start();

this.Close();
}

private void SendData()
{
if (SendData(message))
{
this.Close();
MessageSentForm msf = new MessageSentForm();
msf.ShowDialog();
}
}

SendData is executed and working fine and I get the MessageSentForm().
But I never see the PleaseWaitForm.

Any ideas?
 
C

Chris Tacke, eMVP

Why does that surprise you? Your PleaseWaitForm starts a thread in Load and
then closes itself. My guess is that would only take a few milliseconds to
run and it never get painted. Thread.Start is not synchronous - if it were
there would be no point in having a thread. Architecturally the worker
thread shouldn't be owned by that dialog either.

My guess is that you need to read up more on how threads work.


--

Chris Tacke, Embedded MVP
OpenNETCF Consulting
Giving back to the embedded community
http://community.OpenNETCF.com
 
C

Cub71

You're right about that, it surprises me because I don't know better.
Thats what these forums are there for isn't it? ;-)

The sending of data takes about two to four seconds. Enough to make
you wonder what is not happening after hitting "Send".

In the full version of .Net Framework I would have used Form.Shown()
but here I can't find an event that triggers after the form has been
drawn. What should I do to achieve this?
 
C

Cub71

Tried both these:

public PleaseWaitForm(string inParam)
{
InitializeComponent();
message = inParam;
this.Activate();
}

and

private void PleaseWaitForm_Load(object sender, EventArgs e)
{

this.Activate();
}


None of these work either. But the message is sent and the next form
is shown after this:

In the PleaseWaitForm:

if (SendData(message))
{
this.Close();
MessageSentForm msf = new MessageSentForm();
msf.ShowDialog();
}


Maybe I should investigate a little on this?:

private void PleaseWaitForm_Load(object sender, EventArgs e)
{

this.Activate();
ThreadStart starter = new ThreadStart(this.SendData);
Thread t = new Thread(starter);
t.Start();
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top