Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 612099
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T17:51:23+00:00 2026-05-13T17:51:23+00:00

EDIT: this is a winform application, sorry for the inconvenience Disclaimer: this is an

  • 0

EDIT: this is a winform application, sorry for the inconvenience

Disclaimer: this is an assignment we got in college, and I’m stuck over this particular section of code.

I have 2 solutions in Visual Studio 2008, one for a Form and one for a DLL which the form can use for functionality. The idea is to send HTML mails from the client, and to use the Delegate to confirm this.

One class of the DLL contains nothing else but a single Delegate:

namespace Console.Grand
{
    public delegate void ObserverDelegate(string info);
}

In a file called Delegate.cs

In the form, I have the following method which I will use for the Delegate:

private void Update(string info)
{
   this.logBox.Text += Environment.NewLine + info;
}

The logBox variable is a TextArea on the form.

On transmitting, the following occurs(BL stands for “Business Layer”):

BL_MailOut bm = new BL_MailOut(s1,ListViewAdresses());
ObserverDelegate deleg = new ObserverDelegate(Update);
bm.SendMail(deleg);

The BL_MailOut constructor looks like this(we’re in the DLL now):

public BL_MailOut(StandardPage page, List<MailAddress> list)
{
    this.s = page;
    this.adresslist = new List<MailAddress>();
    foreach (MailAddress m in list)
    {
        this.adresslist.Add(m);
    }
}

And the method SendMail:

public void SendMail(ObserverDelegate deleg)
{
    IO_MailOut im = new IO_MailOut(s, adresslist, deleg);
    Thread t = new Thread(new ThreadStart(im.Send));
    t.Start();
}

And finally, we arrive at the method Send():

public void Send()
{
    SmtpClient sc;
    MailMessage msg;
    string info;
    foreach (MailAddress adress in this.list)
    {
        try
        {
            sc = new SmtpClient(HOST);
            msg = new MailMessage(SENDER, adress.Address);
            msg.IsBodyHtml = true;
            msg.Subject = "test";
            msg.Body = page.ToString();
            sc.Send(msg);
            info = "(" + DateTime.Now + ") MAIL SENT TO" + Environment.NewLine + adress.Address;
            deleg(info);
        }
    }

I do catch the needed errors, I just left that out here to save room.

When deleg(info); is reached, expected behavior would be that the textBox receives the needed text. However, it does not. The instance of the delegate is preserved and the compiler gives no error. I’ve read the material on the MSDN site on Delegates, but nothing there helped.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T17:51:24+00:00Added an answer on May 13, 2026 at 5:51 pm

    Your Update method on the form is performing a cross-thread operation, which is not allowed.

    Change your Update method on the form to this

        private void Update(string info)
        {
         ObserverDelegate callBack =  new ObserverDelegate((x) =>
                {
                    this.logBox.Text += Environment.NewLine + info;
                });             
    
            if (this.InvokeRequired)
                this.Invoke(callBack, info);
            else
              callBack(info);
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

(EDIT: This question is now outdated for my particular issue, as Google Code supports
Edit: This was accidentally posted twice. Original: VB.NET Importing Classes I've seen some code
Edit: This code is fine. I found a logic bug somewhere that doesn't exist
I following this article for sending SMS it is a winform application.. I have
Edit: This question was written in 2008, which was like 3 internet ages ago.
EDIT: This was formerly more explicitly titled: - Best solution to stop Kontiki's KHOST.EXE
EDIT: This question is more about language engineering than C++ itself. I used C++
EDIT : This question duplicates How to access the current Subversion build number? (Thanks
Edit: This is a confirmed bug in jQuery 1.3.1. It is fixed in jQuery
I'm using markdown to edit this question right now. In some wikis I used

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.