7 Replies - 2188 Views - Last Post: 26 April 2011 - 02:36 PM Rate Topic: -----

#1 tkksnow   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 26-April 11

Timing and functions

Posted 26 April 2011 - 11:07 AM

Hello,

I'm a novice in c# and having issues solving an issue. I have a aspx page in where a user clicks a submit button to email me with an inquiry. When that button is hit, it starts an function to email me - as well as one to load a processing animated gift. The issue that I have is that it is returning the animated gif after the email is sent (loads when it's all done! not during processing). I haven't been able to figure out how to get around this fooling around with threading as that seems above me at this time.


    public void action(object sender, EventArgs e)
    {

       msg_Click_inquiry_test();
       msg_Click_inquiry();

    }



I want msg_Click_inquiry_test() to change the visible state of my processing gif immediately upon button click. However, it is only shown with msg_Click_inquiry() is finished as well.



    protected void msg_Click_inquiry_test()
    {
        MessagePanel.Visible = false;

        MessagePanelDefault.Visible = true;
        ProcessingAnm.Visible = true;


    }
        

    protected void msg_Click_inquiry()

    {
       

        GridViewRow row = GridView2.SelectedRow;
        string email_text = "User selected the account description " + row.Cells[2].Text + " with the transaction amount of " + row.Cells[3].Text + " of the journal reference " + row.Cells[4].Text + " for department " + row.Cells[6].Text + " which transaction was created on " + row.Cells[7].Text + " with a post date of " + row.Cells[8].Text + ".";
        string email_text_response = MessageBox.Text;

        // EMAIL TIME!

        MailMessage mail = new MailMessage();
        mail.To.Add("x");
        mail.From = new MailAddress(GetDisplayEmail(getAuth()));

        mail.Subject = "New Transaction Inquiry";
        string Body = "User " + getAuth() + " has inquired regarding the following transaction line item: \r\n\r\n"
            + email_text + "\r\n\r\n"
            + "The user gave the following comment: " + email_text_response;

        
        mail.Body = Body;
        
        mail.IsBodyHtml = false;
        SmtpClient smtp = new SmtpClient();
        smtp.Host = "x";
        smtp.Credentials = new System.Net.NetworkCredential
             ("[email protected]", "x");
        //Or your Smtp Email ID and Password
        smtp.EnableSsl = false;
        smtp.Send(mail);
        
        MessagePanelThanks.Visible = true;

    }




Thank you very much for your help.

Is This A Good Question/Topic? 0
  • +

Replies To: Timing and functions

#2 here.to.code   User is offline

  • D.I.C Head

Reputation: 20
  • View blog
  • Posts: 55
  • Joined: 15-February 11

Re: Timing and functions

Posted 26 April 2011 - 11:22 AM

You can try a call back like this if your email processing is on a background thread.

using Systeming.Threading;
...

this.BeginInvoke(new ThreadStart(() =>
{
    ProcessingAnm.Visible = true;
}));


This post has been edited by here.to.code: 26 April 2011 - 11:25 AM

Was This Post Helpful? 0
  • +
  • -

#3 tlhIn`toq   User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6536
  • View blog
  • Posts: 14,450
  • Joined: 02-June 10

Re: Timing and functions

Posted 26 April 2011 - 11:23 AM

The GUI is much slower to respond than most people think.
All of your code is happening on the same thread as your GUI controls so it doesn't get a moment of idle time to make an update.

Add aplication.doevents() to force it.

protected void msg_Click_inquiry_test()
{
    MessagePanel.Visible = false;

    MessagePanelDefault.Visible = true;
    ProcessingAnm.Visible = true;
    Application.DoEvents();
}



The right approach would be to do this multi-threaded.
But this will have to suffice since you state you aren't ready for that.
Was This Post Helpful? 0
  • +
  • -

#4 tkksnow   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 26-April 11

Re: Timing and functions

Posted 26 April 2011 - 11:36 AM

Thanks for the reply! Added it and added to references. Error of :Error 1 'System.Web.HttpApplicationState' does not contain a definition for 'DoEvents' and no extension method 'DoEvents' accepting a first argument of type 'System.Web.HttpApplicationState' could be found.
Was This Post Helpful? 0
  • +
  • -

#5 eclipsed4utoo   User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1536
  • View blog
  • Posts: 5,972
  • Joined: 21-March 08

Re: Timing and functions

Posted 26 April 2011 - 11:38 AM

Since this is for ASP.Net, I moved it to the ASP.Net forum, so you can get solutions that will actually work for ASP.Net.

View Posttkksnow, on 26 April 2011 - 02:36 PM, said:

Thanks for the reply! Added it and added to references. Error of :Error 1 'System.Web.HttpApplicationState' does not contain a definition for 'DoEvents' and no extension method 'DoEvents' accepting a first argument of type 'System.Web.HttpApplicationState' could be found.


There is a reason we have separate forums for C# and ASP.Net. While you are looking for C# solutions, your solution is tightly coupled with the fact that you are using ASP.Net. This means that your solution will be totally different than it would in Windows development. The Application.DoEvents is for WinForms.
Was This Post Helpful? 0
  • +
  • -

#6 tkksnow   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 26-April 11

Re: Timing and functions

Posted 26 April 2011 - 11:39 AM

View Posteclipsed4utoo, on 26 April 2011 - 11:38 AM, said:

Since this is for ASP.Net, I moved it to the ASP.Net forum, so you can get solutions that will actually work for ASP.Net.

View Posttkksnow, on 26 April 2011 - 02:36 PM, said:

Thanks for the reply! Added it and added to references. Error of :Error 1 'System.Web.HttpApplicationState' does not contain a definition for 'DoEvents' and no extension method 'DoEvents' accepting a first argument of type 'System.Web.HttpApplicationState' could be found.


There is a reason we have separate forums for C# and ASP.Net. While you are looking for C# solutions, your solution is tightly coupled with the fact that you are using ASP.Net. This means that your solution will be totally different than it would in Windows development.


Yes, thank you for the forum move. My apologies for using the wrong general c# forum rather than the asp.net.
Was This Post Helpful? 0
  • +
  • -

#7 eclipsed4utoo   User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1536
  • View blog
  • Posts: 5,972
  • Joined: 21-March 08

Re: Timing and functions

Posted 26 April 2011 - 11:41 AM

One solution is to use a continuous progress bar and AJAX to show a "wait cursor" while your email stuff finishes. I wrote tutorial on doing this.
Was This Post Helpful? 1
  • +
  • -

#8 tkksnow   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 26-April 11

Re: Timing and functions

Posted 26 April 2011 - 02:36 PM

View Posteclipsed4utoo, on 26 April 2011 - 11:41 AM, said:

One solution is to use a continuous progress bar and AJAX to show a "wait cursor" while your email stuff finishes. I wrote tutorial on doing this.


Thanks a bunch. I installed the Ajax toolkit and using your tutorial got it to work perfectly. This will be very handy.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1