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 8853963
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:46:28+00:00 2026-06-14T13:46:28+00:00

I need to pass data with an event. Currently, when receiving more data (via

  • 0

I need to pass data with an event. Currently, when receiving more data (via comport), the event will fire but the previous event (&data) is not handled yet, so the data gets overwritten.
How can I handle the event &data in a safe way? I have multiple events like this (15x), so I am not sure if using a queue for the data is the best way or pass data along with the event (like S.O. item 4215845).

Example (this example is with a string, but I also use arrays, bools etc):

At the ‘sender’ side (class1):

public event EventHandler evDiaStringMessage = delegate { };
private void evDiaStringMessageEvent()
{
    evDiaStringMessage(this, new EventArgs());
}
private static string _DiaString;
public string DiaString
{
    get { return _DiaString; }
    set { _DiaString = value; }
}

DiaString contains the data and gets overwritten when evDiaStringMessage is fired too soon.

At the ‘receiver / GUI’ side (class2):

dia.evDiaStringMessage += new EventHandler(dia_evDiaStringMessage);

private delegate void dia_evDiaStringMessageCallBack(object sender, EventArgs e);
void dia_evDiaStringMessage(object sender, EventArgs e)
{
    if (this.InvokeRequired)
    {
        this.BeginInvoke(new dia_evDiaStringMessageCallBack(dia_evDiaStringMessage), new object[] { sender, e});
    }
    else
    {
        frmcomm.CommTextBox("Receiver message: " + dia.DiaString + "\r\n", Color.Red);
    }
}

dia.DiaString does not contain the expected data (previous data), but all events are ‘received’.

Your help is very much appreciated! Even more with an example!

Edit:

I changed the code to:

At the ‘sender’ side (class1):

public event EventHandler<DiaStringEventArgs> evDiaStringMessage ;
public class DiaStringEventArgs : EventArgs
{
    public string DiaString  { get; set; }
}

private void evDiaStringMessageEvent(DiaStringEventArgs e)
{
    EventHandler<DiaStringEventArgs> handler = evDiaStringMessage;
    if (handler != null)
        handler(this, e);
}

…

private void PrepareDataAndFireEvent()
{
    DiaStringEventArgs args = new DiaStringEventArgs(); 
    args.DiaString = ByteToString(data);
    evDiaStringMessageEvent(args);
}

At the ‘receiver / GUI’ side (class2):

dia.evDiaStringMessage += new EventHandler<ifDiA10.DiaStringEventArgs>(dia_evDiaStringMessage);

private delegate void dia_evDiaStringMessageCallBack(object sender, ifDiA10.DiaStringEventArgs e);
void dia_evDiaStringMessage(object sender, ifDiA10.DiaStringEventArgs e)
{
    if (this.InvokeRequired)
    {
        this.BeginInvoke(new dia_evDiaStringMessageCallBack(dia_evDiaStringMessage), new object[] { sender, e});
    }
    else
    {
        frmcomm.CommTextBox("Receiver message: " + e.DiaString + "\r\n", Color.Red);
    }
}
  • 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-06-14T13:46:29+00:00Added an answer on June 14, 2026 at 1:46 pm

    You can store your data in a custom EventArgs class:

    public class ReceivedDataEventArgs : EventArgs
    {
       // Add the properties you require
    }
    

    The event is defined like so:

    public event EventHandler<ReceivedDataEventArgs> ReceivedData;
    

    Your handler will take in an instance your class instead of the EventArgs object, and hence you’ll have the correct data.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to pass data to a variable in my master page each time
I have a server script that I need to pass data to from the
I need to pass audio data into a 3rd party system as a 16bit
I am writing some and I need to pass a complicated data structure to
I'm writing a web application where I need to pass some user data to
I need to pass a complex object representing a data filter to an action
I need to be able to pass HTML data into Outlook like this: MailMessage
So I've got a situation where I need to pass a bunch of data
I have posted my class below and with sample data. I need to pass
I need to pass an extra parameter :mobilejs => true from jQuery to a

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.