event-handling

Object disposal and garbage collection prior to event triggering

蓝咒 提交于 2019-12-20 04:12:17
问题 A piece of code was brought up by someone I was talking to: private void DownloadInformation(string id) { using (WebClient wc = new WebClient()) { wc.DownloadStringCompleted += new DownloadStringCompletedEventHandler(DownloadStringCompleted); wc.DownloadStringAsync(new Uri("http://www.fake.com/" + id)); } } The above is a simplified version of this: (I have the author's permission to post the image.) What bothers me about that code is that an event handler is attached, DownloadStringAsync()

C# to VB: Class.Event += (sender, args) => FunctionName(params)

那年仲夏 提交于 2019-12-20 02:58:14
问题 I'm trying to convert the C# code from this webpage to VB. Everything seems to have converted pretty much fine using an online converter tool, but then I reach the following line: fadeOutAnimation.Completed += (sender, args) => OnFadeOutAnimationCompleted(d, hostGrid, grid); The fadeOutAnimation.Completed event produces an event with the signature (sender, args), and d, hostGrid and grid are variables local to the function containing this mysterious event handler assignment. I think I can see

Using Events Delegates in multi tenant web application

∥☆過路亽.° 提交于 2019-12-20 02:56:05
问题 I'm developing a multi tenant n-tier web application using asp.net Mvc 5. In my service layer I am defining custom events for every important action and raising these events once these actions are executed. For example Public event EventHandler EntityCreated; Public void Create(Entity item) { Save(item); ...... EntityCreated(this, item); } I intend on hooking up business rules and notifications to these events. The main reason I want to use events is decoupling of the logic and easy plug

Still having problems understanding ASP.NET events. What's the point of them?

只谈情不闲聊 提交于 2019-12-20 02:15:08
问题 Maybe I'm slow, but I just don't get why you would ever use an event that is not derived from an actual action (like clicking). Why go through the rigamarole of creating delegates and events when you can just call a method? It seems like when you create an event, all you're doing is creating a way for the caller to go through some complicated process to call a simple method. And the caller has to raise the event themselves! I don't get it. Or maybe I'm just not grasping the concept. I get the

Getting a DataRow from an ASP.NET GridView

只谈情不闲聊 提交于 2019-12-20 01:38:36
问题 I have an ASP.NET GridView that's bound to an ObjectDataSource (which is bound to a MySQL database). On this grid, I have 2 unbound ButtonField columns that I want to trigger server-side events. Hence I have added an eventhandler method to the GridView 's RowCommand event. In the code of said eventhandler, I need to somehow get hold of the underlying DataRow that was clicked on by the user. However, I can't seem to get this to work; if I use code like the following the selectedRow variable is

How can I simulate the press of a button?

吃可爱长大的小学妹 提交于 2019-12-19 19:44:23
问题 I want to test some forms. Is there a way to simulate the press of an Ok (or Cancel) button so that the button is pressed and fires the event handlers that are associated with it? 回答1: The cleanest approach is to call the Click method of the button. This is better than the alternatives for these reasons: You could read the OnClick property, check that it was not nil, and then call the method. But that seems rather pointless since the Click method already does just that. There's no point

How to cancel any event in winforms?

痴心易碎 提交于 2019-12-19 17:38:13
问题 I want to cancel an event from within that function scope. Eg. I pressed button click event and on false validation, I want to cancel this event. Likewise i want to cancel other events also. How can i do this in C# 回答1: It depends on the scenario; in most cases: rather than cancel the event, just do nothing, for example: private void SaveDataClicked(object sender, EventArgs args) { if(!ValidateData()) return; // [snip: code that does stuff] } or: private void SaveDataClicked(object sender,

Updating GUI items upon an event raised by a thread of another class VB.nET

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-19 11:39:06
问题 How to update data in GUI with messages that are being received by a thread of another class ? I have a class with a thread that receives data from a server. This thread raises an event whenever it gets a message from the server. This event is handled inside the Starter Class (main class which contains the GUI). The event handler (say DisplayData() has to display the message received by the other class. My code is like this Class GUI receiverObj = New Receiver() Addhandler receiverObj

How to wait for COM port receive event before sending more data in a loop

吃可爱长大的小学妹 提交于 2019-12-19 11:35:49
问题 I'm working on a small component for writing and reading AT Commands using an old Sony Ericsson phone. Sending and writing to/from the phone is no problem at all, however I would like to be able to pause my SendATCmd function and wait for the COM Port component to notify me with a Notification Event, and then resume the SendATCmd function again. Scenario: I want to get the count of SMS messages in the phone. Normally I'd just tell the phone: Hey, how many SMS messages do you have? and the

Disable middle mouse click

倾然丶 夕夏残阳落幕 提交于 2019-12-19 10:52:09
问题 I need your help in one question that how to disable the middle mouse click on any link to open a new tab in IE 7,8,9. I have tried many thing like return false; e.cancelBubble = true;e.returnValue = false; But not able to stop that feature of IE to open New tab.But if i am putting alert message e if (event.button == 4) { alert("shashank"); } I am able to stop to open new tab .But I don't want to use alert message. 回答1: You can try with following: $(document).mousedown(function(e){ if(e.which