|
tobriain wrote: I have to implement an interface defined in an external program. The deal is that I have a method Notify() in my object that implements that interface, and that when there's an update, that method is called. I can then collect any updates with a method call that returns a System.Array consisting of an ID (given by me when implementing the connection), and a value. There'll be at least 20 different IDs, and the events will be unsorted in the array. I have to either update variables in the 20 objects (maybe stored in some kind of collection with the ID) or define 20 events, and store them in some sort of list for hashing.
Just so I understand... After the Notify method is called, you then call a method that returns an array of objects. Each object has an ID and a value property? Is that close?
tobriain wrote: Can I test for the speed of some of the ideas I have for the design (i don't now too much about the details of some of the objects I could use)?
You could try the Stopwatch class in System.Diagnostics . Start/Stop it at strategic points in your code. Write the elapsed time to the Debug.WriteLine method. This will show up in the debug output window pane.
|
|
|
|
|
Thanks for the swift and helpful replies.
>Just so I understand... After the Notify method is called, you then call a >method that returns an array of objects. Each object has an ID and a value >property? Is that close?
Leslie has articulated the problem better than I actually did. I'm limited by the interface i've to implement - i collect an array of IDs and values.
>If the action needed for each ID is different, and IDs cover a limited range of
>integers, I would consider an array of delegates and call the one that >corresponds to the ID at hand.
There's only four delegates, so if it's faster to search an array with the ID than a hastable to get the right object, i'll do that. Next problem: which is more efficient: firing events with the update values (referenced to delegates/then public accessor methods in the objects), or just setting the values by a call to the public accessor method of the object found in the array/hashtable myself straight away?
>Final remark: how is speed important ? are you concerned about throughput
>(events per second), or latency (reaction time, from event received to event >handled) ?
Both are important, unfortunately. . The speed concern is because of the fact that I'll have a long hierarchy of subscribers to different events fired as a result of the updates, and don't want to be sitting waiting for the method to return before going to the next row in the update array. . . It's important that the events happen in the right order, so I want (for the moment) the updates to be done sequentially. If I start doing begininvoke on the invocation list, I've no guarantee that anything will happen in order without a serious amount of synchronisation.
Hopefully it seems clearer. I'd appreciate any help on this.
Regards,
Tom.
|
|
|
|
|
I'm taking a shot in the dark here because I still may not completely understand your problem. However, that's never stopped me in the past.
I would keep a collection of objects for each ID. Actually, a list of lists would be appropriate here. Then I'd use a switch statement or a string of if/else statements to update the objects when you receive a notification:
public MyObject
{
objectList = List<List<UpdateableObject>>();
objectList.Add(new List<UpdateableObject>());
objectList[0].Add(new UpdateableObject());
objectList[0].Add(new UpdateableObject());
objectList.Add(new List<UpdateableObject>());
objectList[1].Add(new UpdateableObject());
objectList[1].Add(new UpdateableObject());
}
public void Notify()
{
Update[] updates = GetUpdates();
for(int i = 0; i < updates.Length; i++)
{
if(updates[i].ID == 0)
{
foreach(UpdateableObject obj in objectList[0])
{
obj.Value = updates[i].Value;
}
}
else if(updates[i].ID == 1)
{
foreach(UpdateableObject obj in objectList[1])
{
obj.Value = updates[i].Value;
}
}
}
}
In this case, I'm assuming the ID's are consecutive integers, but the code above doesn't depend on that. The ID's could be anything. If you have a lot of ID's you will have a long string of if/else if statements. But as long as this is isolated to a single place in your code, I wouldn't worry about it.
You can have variations on this by storing the list of updateable objects in a hashtable, as you've mentioned, by the ID. Or use an array of delegates like Luc suggested. I wouldn't create 20+ events that you trigger yourself, though. I think that would be the least efficient way to go. Just my opinion.
|
|
|
|
|
Hi,
I'm working on a screen saver that will log users out if they are outside of their allowed logon hours.
I've done this all ready in vbscript as proof of concept and I'm 95% of the way there in C#.
I'm having trouble getting the user logonHours property. It returns a System.Byte[] that should be 21 bytes. Each bit representing an hour out of the week.
No matter how I get the property it always returns as a object, and I can't access the values of the byte array to sort them out. My current code to get the object looks like this:
object objHours;
DirectoryEntry userDSE = new DirectoryEntry("LDAP://" + userDN);
objHours = userDSE.Properties["logonHours"][0];
The line that creates the object works, and I have tried creating the object 2 or 3 other ways. Through the logonHours object I cannot access the values of the array. I have also used a binary stream to convert the object in to a byte array, but the byte array returns a 48 byte array that I don't trust to stay constant in size. I would prefer to access the values through the object properly.
I need some help. It would be appreciated.
Thanks,
Dwayne.
|
|
|
|
|
i have datagrid that bound to database
when i put that row in my code error appear
datagridview1.rows.add();
i need tro allow usert to put new row just in the case of click new button
i need fast answer
thanks
md_refay
|
|
|
|
|
How or where would i look to get current cpu ussage of a spessific proccess ( in this example winword.exe)
thanks so much
crash
|
|
|
|
|
Task Manager can show you such information.
And you can get access to it programmatically by using the PerformanceCounter class.
|
|
|
|
|
|
hi all ,
i have an open source program from microsoft corporation
(called .Net documentor)this program is an automatic documentor but it have alot of files and i cant use it can any one tell me how to use it and if there is another program that is easier or best or both together
Generator
|
|
|
|
|
|
hi,
i am drawing 3 images using device.DrawUserPrimitive.
what i am trying to do is to set the background as transparent, so that the desktop is visible and on it my 3 images.
the problem is that i don't know how to do it under directx ?
if anyone has any suggestion i would be greatful!
thanks,
andreea
|
|
|
|
|
|
I have two icons. One is for the program and the other will be used for the registry file association for the documents used by the app.
How do you have more than on icon image for an executable?
Thanks,
Mark
|
|
|
|
|
As far as I know an icon cannot be specified from a managed dll/exe
|
|
|
|
|
Giorgi Dalakishvili wrote: As far as I know an icon cannot be specified from a managed dll/exe
I'm not sure what you mean. Executables (.exe,.dll) can have many icons (e.g., shell32.dll). In an registry association you pick one using the icon's position.
For example: C:\Windows\System32\shell32.dll,2
I simply want to know how to embed two icons into my application .exe.
Mark
|
|
|
|
|
Mark F. wrote: Executables (.exe,.dll) can have many icons (e.g., shell32.dll). In an registry association you pick one using the icon's position.
For example: C:\Windows\System32\shell32.dll,2
I know that but if I'm not mistaken you can't choose an if the dll or executable was compiled from a .NET language then you can't choose icon from it
|
|
|
|
|
Add them as embedded resources
only two letters away from being an asset
|
|
|
|
|
|
Hi all,
I have a form which does some TIME TAKING file operations. During this I want the progress bar to run. But the whole form hangs as the machine gets busy with file operations.
I tried to use threading as well but dint work.
Can anyone help please .
Thanks,
Deepa
|
|
|
|
|
You should use multithreading. Have a look at BackGroundWorker component in MSDN. It has quite a good example
|
|
|
|
|
Hey thanks, It worked.
It even worked with threading. The catch was to make the thread to work in background
t.IsBackground=true;
- Deepa
Thanks,
Deepa
|
|
|
|
|
Hello,
I would definitelly recommend the threading approach, allthough it didn't completely solve your problem.
Additionally you could try to call "Application.DoEvents()".
Hope it helps!
All the best,
Martin
|
|
|
|
|
you need to activate the method using Threads :
<br />
private void Method1()<br />
{<br />
Thread t1 = new Thread(ThreadStart(Method2));<br />
t1.Start();<br />
}<br />
<br />
private void Method2()<br />
{<br />
}<br />
<br />
to update the progressBar, you need to invoke another method because of the asynchronous call to Method2() what you need to do is thaat:
<br />
if(progressBar.InvokeRequired)<br />
{<br />
progressBar.Invoke(Method3);<br />
}<br />
else<br />
{<br />
}<br />
<br />
Method3() Bans Cross thread
|
|
|
|
|
Hi im making a client server program so i want to disable some applications in windows like (access internet, see my network places etc) from the client until he become authenticated. So is that possible or what ???
Thanks for ur help
Eng/Bahaa
|
|
|
|
|
You want to disable access to internet and network places from within your application? Then don't call any function that uses it until authernticated.
only two letters away from being an asset
|
|
|
|