|
Hi, im new to C# and have a problem when i must assign methods to objects i create in execution mode.
while in design mode u can create a timer and then double click on it and there u go, but how can i attach a method to a timer i have created in execution time?
<br />
using System.Timers;<br />
<br />
Timer t = new timer(30000);<br />
t.enabled=true;<br />
Ty for ur time.
|
|
|
|
|
Timer t = new Timer(new TimerCallBack(Your Method));
and then handle all the rest
|
|
|
|
|
Declare your Timer
[code]
System.Timers.Timer myTimer = new System.Timers.Timer(1000);
// 1000 is the Interval used by the Timer in ms, i.e. the time between two "Timer.Elapsed" Events
[/code]
Then add an EventHandler
[code]
myTimer.Elapsed +=new System.Timers.ElapsedEventHandler(myTimer_Elapsed);
// Note: In VS.NET 2003, as soon as you type the +=, VS will ask you to press
// TAB. If you do, it will code-complete everything else, even the Delegate's
// body if you press TAB again.
[/code]
Now, on each Elapsed-Event, the Delegate will be executed
[code]
//If you are not using VS.NET, this is what the delegate should look like:
private void myTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
}
[/code]
|
|
|
|
|
TY a lot for your help and examples, it works perfect now.
|
|
|
|
|
I have a tcp server, when a client connects, then let its cable unplugged!
Then How can server detect that it is disconnected?
Thanks all!
|
|
|
|
|
It can't. The only thing it can do is assume that the client dropped the connection without closing it, because of a complete lack of communication for a specified timeout period.
Or, with a little more thought, the server can try and PING the client every so often to see if it is still alive. This has it's problems too considering the client might be behind a firewall that won't let ICMP packets through.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
It isn't really true that the server can't detect that the client disconnected. But the server can't detect it just by sitting there. I had some code somewhere that managed this by having the server periodically switch the socket to nonblocking mode and try to do a read in peek mode. Note that the receive in peek mode might return WSAEWOULDBLOCK if the socket is still live and there is nothing to read on it. But if the socket is closed, it will not return an exception. That is why I preload the bytes[] array with some data that I can then compare the read result against, of course assuming that I would never expect the read to contain that exact byte pattern. There might be a better way, but this worked fine for me.
try
{
// Try doing a dummy read to see if the socket is still alive
bytes[0] = 0xf;
bytes[1] = 0xe;
bytes[2] = 0xd;
bytes[3] = 0xc;
socket.Blocking = false;
socket.Receive(bytes, 0, 4, SocketFlags.Peek);
socket.Blocking = true;
if (bytes[0] == 0xf && bytes[1] == 0xe && bytes[2] == 0xd && bytes[3] == 0xc)
{
// The sender has shut down the socket
bexitreadloop = true;
socket.Close();
form1.DisplaySocketStatusMessage("Lost connection with sender");
break;
}
}
catch (SocketException e)
{
socket.Blocking = true;
int code = e.ErrorCode;
if (e.ErrorCode != WSAEWOULDBLOCK)
{
bexitreadloop = true;
socket.Close();
form1.DisplaySocketStatusMessage("Socket error on read");
break;
}
}
|
|
|
|
|
This is Great, Now I'm working on it.
Thanks for this great reply...
Alper
|
|
|
|
|
im trying to request a web but its needs a proxy with authenticantion i have alredy creat a WebProxy object to setit up the WebRequest.Proxy property but idont know how to configure or setup the WebProxy credentials for this proxy authentification can any one give a hand on this
regards alex
|
|
|
|
|
Hi all,
I have a class that owns a "protected" method (let's say 'Class1'; method: 'AddVar'). Now, I want to use reflection to obtain this class and inherit it to a local class.
Something like:
Public Class LocalClass : Assembly.LoadFrom("..PathToClass1..").GetType("Class1")
I now the line above is too good to be right.
Is what I want even possible? If so, How do I define it?
Thanks
MGKido
|
|
|
|
|
|
To build a class "runtime" using reflection is..."tricky". You need to use classes out of System.Reflection.Emit to dynamically buildup the class and method calls at runtime. Even then, if the protected method is flagged virtual it adds another wrinkle.
All of this is entirely possible (I've done it) but it is not easy nor for the faint of heart.
This leads me to ask this: what are you really trying to do? Isn't the assembly and the class available to derive from? Why bother using reflection to do this at all? You should always avoid solutions that are unnecessarily complex.
|
|
|
|
|
Okay,
1. I almost abandoned the thread because of 2 things:
a. Didn't get any real answers.
b. Managed to do it using a code sample that I (think) dowloaded from this site.
The code uses reflection to display all the methods is a given assembly. I noticed that the code manages to display a protected class (I couldn't even see it - that's why I needed to inherit the class). Then I took the code of getting to the protected class and tried to invoke it. It worked.
For future users looking for the answer - You should use BinsingFlags enumerator to expose the method:
"BindingFlags.NonPublic|BindingFlags.Instance|BindingFlags.InvokeMethod"
|
|
|
|
|
I've made a capture application in c# with DirectShow and I currently obtain an output file. I am now developping a video conferencing application and I would like to transform the capture to obtain a stream instead the output file in order to be able to put this live stream on a serveur. And then the participant of the video conference will be able to read the stream from the serveur.
So, I just want to replace the SetOutputFileName function by a system (even by working directly on the COM object if it's not possible with a c# function) to recover directly the output stream.
Is it possible to obtain a stream in output of a DirectShow capture?
Which method can I use in c# to do this?
Thanks for your help
Julien
|
|
|
|
|
Hey Guys !
Anyone knows how to control the space between characters (kerning) using the graphic libraries provided for the .NET Framework 1.1 ?
Thanks a LOT !!!
|
|
|
|
|
|
Thanks,
And... about Google .... I'm here because my search about this topic has no answers. I'm trying with TextRenderingHint.
Thanks again !
|
|
|
|
|
Hi there,
How do I pick the screen-pixel-color from C#?
More precisely, I want to pick a color from a line drawn on a form.
IE: not a bitmap on the form but a line drawn with e.Graphics.DrawPath(etc).
I tried this forum, Google ... where did I miss it?
Thanks,
Akos
|
|
|
|
|
|
Yeah, but you'r is FAR more complicated. You will have to take that color and search around it looking for pixels of the same, or similar color. Then you'll have to feed the coordinate for all those pixels into some form of a curve fitting algorithm. This, you'll probably find in some univerisity research paper somewhere. Don't ask for a code sample, 'cause I don't have one. Let your fingers do the walking through Google...
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Hi!
AFAIK you'd have to create a screenshot of the form (there are articles here on CP dealing with this). Then you can use GetPixel() for the resulting bitmap.
Regards,
mav
|
|
|
|
|
Why dont you add pencolor property while drawing line and retrieve it as and when required!!
Hope it helps.
MaulikCE
|
|
|
|
|
I'm not quite sure what you mean. I know the color i'm looking for.
What I I don't know is, how do i get the color of a pixel on the screen under the cursor.
Or on another way: how do i get the color of any pixel on the screen?
I know, I could use the API. Is there a way to do it from C#?
Thanks,
A
|
|
|
|
|
I am trying to serialize a simple class over the network.
I found the following error at receiver side.
Additional information: Cannot find the assembly BinaryDataSender, Version=1.0.1934.14107, Culture=neutral, PublicKeyToken=null.
What might be the problem? for this also I tried a lot to find the information regarding this, but in vain.
MOhammed Aijaz MOhiuddin.
|
|
|
|
|
what formatter do you use? SOAP, XML, Binary?
how do you serialize and deserialize your instance?
|
|
|
|