473,748 Members | 7,118 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Event assigned but doesn't fire

Hi,

A quicke summarize:
I made a windows form that can set up a socket connection. It also has
events that fire when data arives. Now I am using this form in a hidden
way inside other code (was the only way I could get the threading to
work for the client without the client needing to test for thread save
stuff) It works in several programs (perfectly), but in a Windows
Services it doesn't fire the event. I used debug lines to check what
went on, it gets to the fireing of the event akts normal (no error) but
the event doesn't get fired.

When I insert this into a windows form I can access the GUI without
getting a conflict about accessing a GUI element from a different thread
than the creator.

private void ServerDataRecei ved(string Message)
{
if (InvokeRequired )
{
object[] pList = { Message };
ReceivedDataTex tBox.BeginInvok e(new
UpdateServerCal lback(DoServerD ataReceived), pList);
}
else
{
DoServerDataRec eived(Message);
}
}
private void DoServerDataRec eived(string Message)
{
ReceivedDataTex tBox.Text = Message;
if (OnMessageRecei vedFromServer != null)
{
OnMessageReceiv edFromServer(th is, Message); <-- It just walks over this
line, no error no event ...
}
else
{
Log.LogError("N o one is listening to OnMessageReceiv edFromServer");
}
}
If anybody know what goes on here or can help me find out what to check,
please :)

-Mark

--
Sent via .NET Newsgroups
http://www.dotnetnewsgroups.com
Nov 17 '05 #1
6 1365
Mark,

If you are running this code in a service, you should not be using a
windows form. You should separate the logic out of the form into other
classes which you can use with your service.

The thing with a service is that it is not guaranteed that there is an
interactive user session that is running which you could attach to in order
to create windows in (and you have to set the service up to specifically
allow that as well).

Bottom line, separate out the logic from your form into classes that you
can use in your service.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Mark Nijhof" <Ma*********@Gm ail.com> wrote in message
news:ec******** ******@TK2MSFTN GP15.phx.gbl...
Hi,

A quicke summarize:
I made a windows form that can set up a socket connection. It also has
events that fire when data arives. Now I am using this form in a hidden
way inside other code (was the only way I could get the threading to
work for the client without the client needing to test for thread save
stuff) It works in several programs (perfectly), but in a Windows
Services it doesn't fire the event. I used debug lines to check what
went on, it gets to the fireing of the event akts normal (no error) but
the event doesn't get fired.

When I insert this into a windows form I can access the GUI without
getting a conflict about accessing a GUI element from a different thread
than the creator.

private void ServerDataRecei ved(string Message)
{
if (InvokeRequired )
{
object[] pList = { Message };
ReceivedDataTex tBox.BeginInvok e(new
UpdateServerCal lback(DoServerD ataReceived), pList);
}
else
{
DoServerDataRec eived(Message);
}
}
private void DoServerDataRec eived(string Message)
{
ReceivedDataTex tBox.Text = Message;
if (OnMessageRecei vedFromServer != null)
{
OnMessageReceiv edFromServer(th is, Message); <-- It just walks over this
line, no error no event ...
}
else
{
Log.LogError("N o one is listening to OnMessageReceiv edFromServer");
}
}
If anybody know what goes on here or can help me find out what to check,
please :)

-Mark

--
Sent via .NET Newsgroups
http://www.dotnetnewsgroups.com

Nov 17 '05 #2
Hi Nicholas,

Thanks for the reply :)

I probably wasn't clear about it, I know it is not the way to do it to
use a Windows Form in a Windows Services. The reason why I do that is
that I want to do the thread syncronasation inside the class. I want to
be able to place this component any where without having to worrie about
the threading part. So that the end user doesn't have to write the
Invoke part when using the component in a GUI enviorment. I am not
Showing the form anywhere, I just need it's capabilities to check wheter
the call is from a different thread.

If you know a way arround it not having to use Windows.Forms than that
would be great.

-Mark
--
Sent via .NET Newsgroups
http://www.dotnetnewsgroups.com
Nov 17 '05 #3
Mark Nijhof <Ma*********@Gm ail.com> wrote:
Thanks for the reply :)

I probably wasn't clear about it, I know it is not the way to do it to
use a Windows Form in a Windows Services. The reason why I do that is
that I want to do the thread syncronasation inside the class. I want to
be able to place this component any where without having to worrie about
the threading part. So that the end user doesn't have to write the
Invoke part when using the component in a GUI enviorment. I am not
Showing the form anywhere, I just need it's capabilities to check wheter
the call is from a different thread.

If you know a way arround it not having to use Windows.Forms than that
would be great.


Basically, you should write an equivalent of a message pump - or
another way of looking at it is a thread-pool with only a single thread
in it.

You just need to wait for data (whether that's in terms of parameters
or delegates or whatever) and use something like Monitor.Wait/Pulse to
get notified when that data arrives.

See half way down
http://www.pobox.com/~skeet/csharp/t...eadlocks.shtml for an
example of a producer/consumer queue which could be handy here. I'd
also suggest implementing ISynchronizeInv oke so that you could pass an
implementation of that around (just as ISynchronizeInv oke) for clients
to use.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Nov 17 '05 #4
Mark,

What you want to do is not really possible without some knowledge of the
environment that you are running in. You sound like you want thread
affinity, not thread synchronization . This is what the ISynchronizeInv oke
interface is for.

Instead of handling that inside your class, I would have your class take
an implementation of ISynchronizeInv oke (through the constructor, on a
property, etc, etc) and then use that to invoke your methods on the
appropriate thread. If it is not passed in, then you execute it on whatever
thread you are called on.

This way, you can pass a control so that you can have your method
execute on the UI thread (be careful about doing this, good design is going
to be important here).

Also, as a general rule, you don't want to encapsulate all of this
threading in a component so that it is black-boxed. Rather, it should be up
to the caller, or the caller should have explicit knowledge of how the
threading is occuring, and affect it, if desired.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Mark Nijhof" <Ma*********@Gm ail.com> wrote in message
news:O0******** ******@tk2msftn gp13.phx.gbl...
Hi Nicholas,

Thanks for the reply :)

I probably wasn't clear about it, I know it is not the way to do it to
use a Windows Form in a Windows Services. The reason why I do that is
that I want to do the thread syncronasation inside the class. I want to
be able to place this component any where without having to worrie about
the threading part. So that the end user doesn't have to write the
Invoke part when using the component in a GUI enviorment. I am not
Showing the form anywhere, I just need it's capabilities to check wheter
the call is from a different thread.

If you know a way arround it not having to use Windows.Forms than that
would be great.

-Mark
--
Sent via .NET Newsgroups
http://www.dotnetnewsgroups.com

Nov 17 '05 #5
Thanks Jon and Nicholas,

I will look into these suggestions first thing tomorrow, I have been
looking arrount too find a better option for this for a while.

Why would you not want to have a black box principle? (it's not for a
comercial product, just trying, learning and understanding) I just want
to have to create the component and I have a socket connection than
listenen for the event and do what I want to do there, wether there is a
gui involved or not.

Thanks for the help, keep watching this toppic, I'll most likely be back
;)

-Mark

--
Sent via .NET Newsgroups
http://www.dotnetnewsgroups.com
Nov 17 '05 #6
Mark,

In programming, black boxes are rarely good things. More often than
not, you find that requirements change, and when things are encapsulated in
such a way, you will have a harder time pulling it all out later. In the
end, the future maintainability is compromised when you do something like
this.

Of course, it is possible that there are conditions that will never, or
are very unlikely to change. If that is the case, then I would assume that
pulling this all together in a black-boxed method would be ok. You are the
only one who can make that decision.

Also, don't reply to this thread. Chances are if you take more than 1/2
a day to respond, it will have scrolled too far up the list (for those that
don't track individual threads) that no one will see it.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Mark Nijhof" <Ma*********@Gm ail.com> wrote in message
news:On******** ******@tk2msftn gp13.phx.gbl...
Thanks Jon and Nicholas,

I will look into these suggestions first thing tomorrow, I have been
looking arrount too find a better option for this for a while.

Why would you not want to have a black box principle? (it's not for a
comercial product, just trying, learning and understanding) I just want
to have to create the component and I have a socket connection than
listenen for the event and do what I want to do there, wether there is a
gui involved or not.

Thanks for the help, keep watching this toppic, I'll most likely be back
;)

-Mark

--
Sent via .NET Newsgroups
http://www.dotnetnewsgroups.com

Nov 17 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
6157
by: JayDee | last post by:
After a user enters data into a field, I need to populate other controls on the form, based on the user entry. I have to use either Leave, Validating or Validated, and I take it I can't use LostFocus because there is no selection for that event in the dropdown list on the code page. What's happening is that all 3 events mentioned above for the textbox control fire in the proper order when the form is invoked, but don't fire the first time...
5
3785
by: Maxine G | last post by:
I have two forms, a menu and a data entry form. The entry form is bound to a query against linked SQL server tables. In the deactivate event, I have some code which asks the user if they want to save their changes and they can respond with yes, no or cancel. If they press cancel, the entry form stays active with the changes still entered. So, if I'm on the entry form and have entered data, and then click on the menu, the deactivate event...
1
1403
by: Sylvain | last post by:
Hi All I need to add a new event at the beginning of an event handler e.g.: I've got a textbox which is assigned an event at design time to the TextChanged eventhandler, but I need to add a new event to it from an other class during run time, and this new event has to be called BEFORE the event assigned at design time. (i.e. I cannot use +=.. I could not find any information on this in the MSDN help, so any Idea please Thank you for your...
6
2207
by: Shimon Sim | last post by:
I have Panel control on the page. I am handling Init event for it. It doesn't seem to fire at all. Why? Thank you Shimon.
5
10369
by: Verde | last post by:
This is admittedly an apparently odd request... but please indulge me if you don't mind: Suppose I have two <asp:Button.../> on a page (Button1 and Button2). User clicks Button1 and triggers a PostBack. How can I then fire the click event of Button2 during the same PostBack? I know this seems like a totally bad situation I'm creating out of naiveity. But please indulge. It would save me from having to provide a lengthy explanation for...
2
1145
by: jeff_mishima | last post by:
Hello, I've got an issue with a dynamically assigned event not actually being assigned correctly to a linkbutton- or at least that appears to be the issue. The linkbutton doesn't work on 1st click, but does on 2nd click. I've tried assigning the event as early in the page cycle as possible (in OnInit() for example), calling the event-assigning function more
2
1789
by: planetthoughtful | last post by:
Hi All, I have a calendar form that updates a date field on the form from which it was called. I have code in the OnChange event of the date field that I would like performed whenever the date value in the field is changed, including when changed by selecting a new date from the calendar form. The calendar form works as expected - when I select a date the date is placed in the date field of the calling form, but the OnChange event...
9
2471
by: jeff | last post by:
New VB user...developer... Situation...simplified... - I want to wrap a pre and post event around a system generated where the pre-event will always execute before the system event and the post event will always execuate after the system is completed... - I want to wrap this functionality in a framework, so I could possibly have 3 or 4 levels of inherited objects that need to have these pre / post events executed before and after the...
8
5027
by: schaf | last post by:
Hi NG! I have a problem in my remote application. After calling a remote function the calculation will be done by the service. The calculation result will be sent to the caller (client) via remote event. The following behavior can be observed: 1.) Right after the start of the server the first response via remote event will take a long time.
0
8984
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8823
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
9312
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9238
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6793
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6073
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4864
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3300
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2775
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.