|
Does delegate creates another thread internally ? or it blocks the further execution until the event is processed fully.
I have to handle few functions parallel so I don't know I should go with threading or (events + delegates)
|
|
|
|
|
You can go with threading for parallel execution. Create a backgroud thread for your functions that run in parallel and does not need any user interactions.
Delegate and events both are kind of "Call the piece of code that I supply when something happened". So it states that your piece code will not guaranteed to run in parallel. But, it will run when delegate in invokes and event is fired.
modified on Friday, October 22, 2010 3:07 AM
|
|
|
|
|
Ok so if "something happens" 2 times immediately and if first handler did not finish it's processing then will it be called again or it will wait inside some "event queue or delegate queue" or it will not call.
|
|
|
|
|
Think of a function calling another function.
Delegate is nothing but a function defined by you. Event also tied up with some handler (again delagate that will be called when an event fired). The code which knows the registered delegate or delegate in the form event handler, just makes a call to the function.
How does the code that tires to notify "Hey.. Something happend"? It will call the delegate you registered to notify. If the "Same thing" of that "Something" happened twice ( Sorry) , it will call your registered routine two times sequentially.
To know the handler run in parallel or sequential, inside your handler put a while loop that run for ten times, and console out some test value. On each iteration put a Sleep(1000) [1 Second]. And, make a conclution based on the result.
Mu Guess is sequential
|
|
|
|
|
Calling a delegate is basically the same as calling the method(s) in the delegate's invocation list directly.
However, if you call BeginInvoke on the delegate, a new thread will be created and the methods will be called on that.
A little demo to show:
using System;
using System.Threading;
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Main Thread");
Console.WriteLine(Thread.CurrentThread.ManagedThreadId);
Test test = new Test();
Console.WriteLine("Direct Method Call");
test.Method();
MethodDelegate methodDelegate = new MethodDelegate(test.Method);
Console.WriteLine("Direct Delegate Call");
methodDelegate();
Console.WriteLine("Delegate Invoke");
methodDelegate.Invoke();
Console.WriteLine("Delegate BeginInvoke");
methodDelegate.BeginInvoke(null, null);
Console.ReadKey();
}
}
public delegate void MethodDelegate();
class Test
{
public void Method()
{
Console.WriteLine(Thread.CurrentThread.ManagedThreadId);
}
}
|
|
|
|
|
Thanks,
I will go for "BeginInvoke"
|
|
|
|
|
|
Could someone give me a direction?
I would like to do a log(output to txt file) of Removable Device.
Currently, I am only able to detect whether is there any Removable Device inserted or removed on the computer.
I need to know how to capture like I have move a file or folder from Removable Device to computer or vice verse.
|
|
|
|
|
You're not he first person to ask this. It comes up about every 6 months...
In a nutshell, there's no way to do this. Since a copy operation is no different than opening a file to read it, for example, opening it in Notepad, there's no way to tell if someone is copying a file or not. A move operation is a bit more complex because if the source and destination is on the same volume, the directory entry is moved to its new folder. If done between different volumes, it becomes a copy operation then delete the source file.
Why can't it be done? Because it can't be done reliably. If Explorer does the copy/move, you may be able to hook the shell to see if happens, but that won't catch someone typing COPY or XCOPY in a CMD prompt, nor will it catch any other program that is doing the copy or move.
|
|
|
|
|
Hi Dave,
Thanks for answering.
What if I just want to do a log when there is a move operation from computer to removable devices like thumb drive?
I do not need to log down the movement of the files locally.
Still able to do it?
|
|
|
|
|
No, you can't. There's nothing different about a USB drive compared to any other disk as far as the file system is concerned. A copy operation is still just open a file, read it's contents, and write it to a destination file. There is nothing that is special about a copy operation that you can use as a trigger.
|
|
|
|
|
Sadded. Anyway thanks. Haha.
|
|
|
|
|
|
Won't work for what he's talking about.
|
|
|
|
|
Sure it won't, Dave, but combined with some heuristic I think he might get a good approximation if he doesn't need an exact solution.
|
|
|
|
|
Nowhere near a reliable solution...
|
|
|
|
|
Thanks alot will try it out
|
|
|
|
|
Hello
I have to user controls on the same window and I would like to call a method in user control B from user control A. The method in user control B is public.
At the moment I have no clue how I would go about doing this. Any help would be greatly apreciated.
|
|
|
|
|
I don't have Visual Studio in the laptop I am currently using. But this should work. Main thing is that you will get the idea as to how to do this.
Assume you the following 2 user controls in your .aspx
ParentPage.aspx
<%@ Register src="Control1.ascx" TagPrefix="uc" TagName="Control1" %>
<%@ Register src="Control2.ascx" TagPrefix="uc" TagName="Control2" %>
<uc:Control1 runat="server" ID="ctrl1" />
<uc:Control2 runat="Server" ID="ctrl2" />
ParentPage.aspx.cs
public partial class ParentPage : Page
{
public Control1 getControl1()
{
return ctrl1;
}
public Control2 getControl2()
{
return ctrl2;
}
}
In the user control you could do the following:
Control1.ascx.cs
public partial class Control1 : UserControl
{
public void Page_Load(...)
{
ParentPage myPage = (ParentPage)this.Parent;
Control2 ctrl2 = myPage.getControl2();
}
}
Hope you understand this. Else post your questions here, when I get to a computer w/ VS, should be a lot easier!
[Edit] While answering this I assumed that you are referring to a web page. This wouldn't be the same for a win forms app (just now i noticed you have said "window" and not "page" and that this is the C# forum and not the ASP.Net forum). But the idea would be similar - instead of page, you would be getting the Form's instance (the parent) which exposes 2 methods to return the user control id's, thereby enabling you to call that control's methods.
Cheers,
Karthik
modified on Thursday, October 21, 2010 11:01 PM
|
|
|
|
|
There are 2 things user control A needs to do:
- Get a reference to user control B (assume it's named
ctrlB and is of type CtrlB ).
- Call the appropriate method (assume it's named
DoSomething() ).
Control ctrlB = this.Parent.Controls.FirstOrDefault (p => p.Name.Equals ("ctrlB"));
Debug.Assert (ctrlB != null);
((CtrlB) ctrlB).DoSomething();
/ravi
|
|
|
|
|
Not sure about why you want to do someting like this, becouse this way your user control A will depend too much on your user control B and vice versa. I guess you should better place an event into your user control A, and make your user control B subscribe to this event.
|
|
|
|
|
I have found a way to do it now but the reason for doing it is because UC A is a custom treeview where an item can be selected and once selected it populates UC B which is a form containing text fields.
|
|
|
|
|
Ok, then I think the best way to go in this case would be subscribing the form to the AfterSelect event (I guess you have inherited the TreeView control) and call the method on your B control whithin this handler.
I am telling you this becouse this way you will be able to reuse your custom treeView in other future projects where, maybe, you might need to populate a different set of controls with some different information.
|
|
|
|
|
Hello guys,
I have an app made that worked with the old Google Keywords Tool External. It worked perfectly until a few days ago when they dropped the new interface. Now I can't seem to crack this myself, and I need some help.
Using opera dragonfly (helps debug http requests) I managed to see how everything looks "in the background" but I don't understand a thing now. With the old site,everything was crystal clear, but now it's not.
The new website is located here:https://adwords.google.com/o/Targeting/Explorer?__u=1000000000&__c=1000000000&ideaRequestType=KEYWORD_IDEAS#search.none
When you want to get keyword results (enter a keyword and press enter), google makes a POST request here:
https://adwords.google.com/o/Targeting/g?__u=1000000000&__c=1000000000
The request headers are:
Host adwords.google.com
User-Agent Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.11) Gecko/20101012 Firefox/3.6.11
Accept text/html,application/xhtml+xml,application/xml;q=0.9,*
Now I don't understand what X-GWT-Permutation is (anx all the other x-gwt). I know it's google web toolkit ... but how the hell can I make a "call"to this website from c# .net (using httprequest) ?
The post content sent is:
6|1|69|https:
How should I send this? Like "uploading" a file? It's not a normal http post, because it has no variables, it's a simple text that it's sent.
So to make things short, I want to "download" the google keyword tool external page, and get the results in C# .net so I can process them.
Can anybody help?
Thanks in advance,
Vlad
|
|
|
|
|
Hi,
I'm not familiar with the Google interfaces, however I managed to do some other POSTs a few weeks ago, and basically this page[^] was all I needed.
sodevrom wrote: It's not a normal http post, because it has no variables, it's a simple text that it's sent.
It doesn't matter what the post data is, just write it to the stream, then proceed with accepting the result using HttpWebRequest.GetResponse() and HttpWebResponse.GetResponseStream() .
So if it worked for you earlier, there should not be a major problem (unless you want to understand what it is you are posting).
|
|
|
|