Click here to Skip to main content
15,896,522 members
Home / Discussions / C#
   

C#

 
GeneralRe: Design pattern ask for advice Pin
George_George25-Oct-08 0:34
George_George25-Oct-08 0:34 
QuestionHow to scroll a listview with scrollable property disabled Pin
vayanan24-Oct-08 0:02
vayanan24-Oct-08 0:02 
AnswerRe: How to scroll a listview with scrollable property disabled Pin
AhsanS24-Oct-08 0:11
AhsanS24-Oct-08 0:11 
GeneralRe: How to scroll a listview with scrollable property disabled Pin
vayanan24-Oct-08 0:16
vayanan24-Oct-08 0:16 
GeneralRe: How to scroll a listview with scrollable property disabled Pin
AhsanS24-Oct-08 0:35
AhsanS24-Oct-08 0:35 
AnswerRe: How to scroll a listview with scrollable property disabled Pin
Eddy Vluggen24-Oct-08 0:15
professionalEddy Vluggen24-Oct-08 0:15 
AnswerRe: How to scroll a listview with scrollable property disabled Pin
Simon P Stevens24-Oct-08 0:37
Simon P Stevens24-Oct-08 0:37 
QuestionBeginReceive: How do I get out of the thread when reachig callback function? Pin
Kurt23-Oct-08 23:41
Kurt23-Oct-08 23:41 
BeginReceive is used in my class for receiving data over TCP/IP.
When reaching the callback of BeginReceive, the class fires an event and puts the received data in the EventArgs.

I use the class in a Form that displays received data. But I can't show the data without Invoke.

Does anyone know how to fire the Event without the necessity of Invoke outside the class?

class1 (receives TCP/IP data)
{
  public event EventHandlerDataReceived DataReceived;
  private byte[] recPacket = new byte[32000];

  private void WaitForData()
  {
    // Async receiving
    sockClient.BeginReceive(recPacket, 0, recPacket.Length, SocketFlags.None, new AsyncCallback(OnDataReceived), null);
  }

  private void OnDataReceived(IAsyncResult asyn)
  { 
    // Async callback 
    sockClient.EndReceive(asyn)
    OnDataReceived(this, new DataReveivedEventArgs(recPacket)
  }

  public void OnDataReceived(object sender, DataReveivedEventArgs e)
  {
    // Fire event that carries reveived Data in EventArgs
    if (DataReceived != null) { DataReceived(this, e); }
  }

class2 (Form)
{
  class1 tcpClass = new class1();
  
  public class2()
  {
    // Initialisation of event 
    tcpClass.DataReceived += new tcpClass.EventHandlerDataReceived(tcpClass_DataReceived);
  }

  private void tcpClass_DataReceived(object sender, DataReveivedEventArgs e)
  {
    // Problem: Can't get off from the thread BeginReceive
    // Invoke would be necessary. That makes usage of class1 very uncomfortable.

    txtData.Text = e.Data.ToString();
  }
}

AnswerRe: BeginReceive: How do I get out of the thread when reachig callback function? Pin
Simon P Stevens24-Oct-08 0:20
Simon P Stevens24-Oct-08 0:20 
GeneralRe: BeginReceive: How do I get out of the thread when reachig callback function? Pin
Kurt24-Oct-08 0:35
Kurt24-Oct-08 0:35 
GeneralRe: BeginReceive: How do I get out of the thread when reachig callback function? Pin
Simon P Stevens24-Oct-08 0:42
Simon P Stevens24-Oct-08 0:42 
GeneralWhy don't we need invoke events of controls? Pin
Kurt24-Oct-08 1:41
Kurt24-Oct-08 1:41 
GeneralRe: Why don't we need invoke events of controls? Pin
Simon P Stevens24-Oct-08 1:53
Simon P Stevens24-Oct-08 1:53 
AnswerRe: BeginReceive: How do I get out of the thread when reachig callback function? Pin
Gideon Engelberth24-Oct-08 3:04
Gideon Engelberth24-Oct-08 3:04 
AnswerRe: BeginReceive: How do I get out of the thread when reachig callback function? [modified] Pin
Alan N24-Oct-08 8:13
Alan N24-Oct-08 8:13 
AnswerSolution incl. example :-) Pin
Kurt27-Oct-08 0:50
Kurt27-Oct-08 0:50 
QuestionOpen-source C# shopping cart Pin
Andrey Mazoulnitsyn23-Oct-08 22:49
Andrey Mazoulnitsyn23-Oct-08 22:49 
QuestionAccess different variable names on the fly Pin
J-Cod3r23-Oct-08 20:55
J-Cod3r23-Oct-08 20:55 
AnswerRe: Access different variable names on the fly Pin
Eduard Keilholz23-Oct-08 21:44
Eduard Keilholz23-Oct-08 21:44 
AnswerRe: Access different variable names on the fly Pin
N a v a n e e t h23-Oct-08 22:42
N a v a n e e t h23-Oct-08 22:42 
AnswerRe: Access different variable names on the fly Pin
PIEBALDconsult24-Oct-08 4:32
mvePIEBALDconsult24-Oct-08 4:32 
QuestionAuto Generate Customer ID Pin
nt_virus23-Oct-08 18:12
nt_virus23-Oct-08 18:12 
AnswerRe: Auto Generate Customer ID Pin
AhsanS23-Oct-08 20:16
AhsanS23-Oct-08 20:16 
AnswerRe: Auto Generate Customer ID Pin
N a v a n e e t h23-Oct-08 20:42
N a v a n e e t h23-Oct-08 20:42 
AnswerRe: Auto Generate Customer ID Pin
V.23-Oct-08 22:24
professionalV.23-Oct-08 22:24 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.