.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links

Events not being fired from client class

Posted By:      Posted Date: May 22, 2011    Points: 0   Category :WPF

Hello! I will try to keep this as short and concise as possible.

I am working on a client-server application. Everything worked well, the client (which consisted of a form at that time) got the events from the server, but the problem was that I was doing everything in the form class. So I thought that it would be nicer to create a 'Client' class which the form would use. All the code would go in the Client class and the form class would just call one or two methods.

Now, my Client class gets the events from the server, does something with the data, and fires its own events which should be picked up by the form class, but that doesn`t happen. I experimented a bit, trying to fire events from different classes, changed some code here and there and came to the conclusion that if my Client class inherits from Control, the form class will pick up the events fired from the Client class.My questions is the following: what exactly should i add to my Client class (the necessary minimum) in order for the events to work properly? Inheriting from Control just to make the events work seems a bit too much.

Edit: I tracked it down and the 'most base' class that I have to inherit from is MarshalByRefObj. Is this always necessary in cases such as mine? And if yes, why? 

View Complete Post

More Related Resource Links

Basic Instincts: Programming Events of the Framework Class Libraries


Some practical examples of handling some of the more commonly used events in the Microsoft .NET Framework.

Ted Pattison

MSDN Magazine May 2003

ASP.NET: Using a static class and methods for the WCF client

Traditionally in our web pages we have instantiated a service client in each page and then called the WCF methods from that instance, adding some caching code to check if the data exists and if not, make the WCF call and cache the data for the next time. As our site grows we find we're repeating this same pattern and are looking to move it all to a single class. Can we make that class static, with a single static instance of the WCF client, and static methods, safely? // pseudo-code // assume WcfDataService has a GetFoo(int i) method public static class WcfMethods { public static WcfDataService client = new WcfDataService("connectionType"); public static DataSet GetFoo(int i) { if (Cache["foo" + i] == null) { Cache.Insert("foo" + i, client.GetFoo(i)); } return Cache["foo" + i] as DataSet; } } Then in our pages we can just call WcfMethods.GetFoo(x) directly.  Figure we have 100 users visiting our various pages simultaneously.  Will this cause contention issues?  Like I mentioned, up till now we've not used static instances.  It's not caused any problems, but we're just looking to refactor.  I realize we could also use the above pseudo-code pattern using an instance class and methods instead static ones. I haven't dealt with threading or synchro

C# Thread Safe Class events

Right now I have created a custom base class that has numerous events.  These events have non-standard signatures and are fired from a thread I have that is basically just a while loop checking variables against older ones for telling when something has changed. As far as I know this is the best way to go about doing this is to just make a void on another thread in a while (true) loop, in the loop just doing ifs... than doing a thread sleep.  I make sure the thread is a background thread that way it'll exit propertly when the consumer exits.  If anyone knows a beter way of going about this than stop reading here. :) If not that onto my real question... I have events that are fired from this loop on the thread I created, now they're attatched on the consumer app and no matter what I do I can't seem to get these events to be thread-safe so that I don't have to use the Control.Invoke method for each event. If anyone knows anything that'll help me out it'll be much appreciated. Thanks,Chad

Raising events of base class


I have base class with public event:

public abstract class MessageProcessor
        public event EventHandler<MessageEventArgs> MessageReceived;


And I want to raise this event from derived class:

public class Device:MessageProcessor

        void timerAlive_Elapsed(object sender, ElapsedEventArgs e)
            MessageReceived(this, null); //compilation-time error here



Error :The event 'WorkServerClasses.MessageProcessor.MessageReceived' can only appear on the left hand side of += or -= (except when used from within the type 'WorkServerClasses.MessageProcessor')

How can I resolve this?

Why events are not fired in this Server Control ?


I have a server control which consists of another server control with a custom navigation panel  with 4 buttons for Next, Previous,.. and a GridView.  I'm trying to publicate events of the image buttons of the navigation panel in order to update the GridView pagination in the outter Server control, but image buttons events are not beig fired. See code bellow, just for MoveNext(). Thanks a lot in advance.

public class cSCGridNavigatorPanel: WebControl, INamingContainer
  protected ImageButton fbtnNext;
  public event ImageClickEventHandler btnNext_Click;
  protected void fbtnNext_Click(object sender, ImageClickEventArgs e)
    if (btnNext_Click != null)
      btnNext_Click(sender, e);

  protected override void CreateChildControls()
    fbtnFirst = new ImageButton();
    fbtnFirst.Click += new ImageClickEventHandler(fbtnFirst_Click); 
  protected override void Render(HtmlTextWriter writer)

consume WCF events from java client??




is there a way to consume WCF services with events from a Java Client?



Visita mí BlOg y Colabora con tus comentarios ;-) Gracias.

Error while using Silverlight class library in .NET 4 Client Profile project


Failed to figure out where to post this problem.

I have two projects in solution: Silverlight 4 assembly and Console application targeted .NET 4 Client Profile. There's an interface in Silverlight assembly which has a return value typed IEnumerable<IPEndPoint>. In console application I'm trying to implement this interface. I have the following error compiling console application project: 'PeerToPeerNameResolver' does not implement interface member 'INameResolver.Resolve(string)'. 'PeerToPeerNameResolver.Resolve(string)' cannot implement 'INameResolver.Resolve(string)' because it does not have the matching return type of 'System.Collections.Generic.IEnumerable<System.Net.IPEndPoint>'

I've never defined my own class IPEndPoint, nor IEnumerable<T> interface. How can I get rid of this error? Method code is 

		public IEnumerable<IPEndPoint> Resolve(string name)
var peername = new PeerName(name, PeerNameType.Unsecured);

Item level events not fired when items are added by routing



 I want to set item level permission in a library. Therefore I developed an itemceiver that should catch new items in that library. My problem: no event is fired (I tried ItemAdding, ItemAdded, ItemUpdating, Itemupdating, ItemCheckingIn, ItemCheckedIn) . All items get into the library through routing, that means, the item is first stored in a dropofflibrary, than routed in my library where I want to set the permission. Probably the events are not fired by routing.The events are fired correctly, when I update or check in an item as soon as they are edited in my library.

Is there a way to set item level permission when routing is used?

Many thanks in advanced.



Adding IServiceClient interface to generated proxy service client class

would it be possible to add a service client interface to a generated service client class in a generated service proxy in order to achieve easier testability?
Here's an example of what I am asking the way I do it manually http://blog.vuscode.com/malovicn/archive/2009/11/01/design-for-testability-wcf-proxies.aspx

This would not break backward compatibility (safe to be added)

Is this question more for Connect? :)


Use jQuery and ASP.NET AJAX to build a client side Repeater

By sending only data to the client, you can profoundly reduce the size of what you send and see a substantial increase in performance. You also allow yourself the ability to easily add features like light-weight sorting and paging on the client. This can not only improve your users' experience, but reduce server load and bandwidth requirements.

Client Side Gridview Pagination using JQuery

I would like to show how to use Client Side Gridview Pagination using Jquery Table Pagination Plugin by using Ryan Zielke.

Use jQuery and ASP.NET AJAX to build a client side Repeater

By sending only data to the client, you can profoundly reduce the size of what you send and see a substantial increase in performance. You also allow yourself the ability to easily add features like light-weight sorting and paging on the client. This can not only improve your users' experience, but reduce server load and bandwidth requirements.

To that end, I'm going to walk you through these four steps to effectively implementing a client side Repeater, using ASP.NET AJAX and jQuery:

Class Diagrams

Class diagrams show the static structure of the systems. Classes define the properties of the objects which belong to them. These include:

Attributes - (second container) the data properties of the classes including type, default value and constraints.

WCF Tutorial - Events and Callbacks

we described how to make a very simple client/server application where clients would call functions on the server through a shared interface. In this tutorial, I'm going to expand that application to allow the server to execute functions on the client by using callbacks. Essentially, this is WCF's mechanism to allow events to be raised from the server to it's connected clients.

Practical Multithreading for Client Apps

Writing applications that use multiple threads is often considered an advanced programming task, prone to errors. In this month's column, I'll focus on a practical application of multithreading in Windows® Forms applications with some real benefits, while attempting to keep things simple. My goal is to present multithreading in an approachable way that addresses a very common need: writing applications with a user interface that remain responsive to the user.

Creating a Simple Class in C#

The second article in the C# Object-Oriented Programming tutorial describes how classes are created in C# and how behaviour, in the form of publicly visible and private, hidden methods can be added. This demonstrates some of the uses of encapsulation

Static Class for Beginners

In general, the members of a class can be accessed by instance of that class when they are in public, but there comes a situation to access or call members of a class without an instance and this can be achieved by declaring them as static
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend