|
That's not entirely true. If questions about third-party controls show up, most of us tell the people to see the documentation for the third-party controls. For one, we may not know those controls (hell, there's hundreds if not thousands of third-party controls for the .NET Framework already...and good ones are all I'm counting). Second, that company should support their own work.
Also, C# questions relating to Windows Forms, graphics, etc., still use C#. ASP.NET is a culmination of a managed language, HTML, XML, etc. It's really in a class all its own, and since there's a specific forum for ASP.NET, such questions should be directed there.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi,
I've got an application which responds to WM_COMMAND Message with some defined Wparams
Now I am writing a service in .NET which should control that application by sending him messages.
The question is: how do I send a message to a window? I already created the message using the Message class, obtained the handler of the window of the desired application, but still the sending part is missed.
can u help me?
DavidR
|
|
|
|
|
I'm not sure on what type of application you are creating, but if I were you, I would try to simply make a function to the child that can be called from the parent's instance to send the message. In other words
ChildInstance.sendData(params)
Wouldn't that work?
|
|
|
|
|
You simply P/Invoke SendMessage . See http://pinvoke.net/default.aspx/user32.SendMessage[^] for the syntax. This is how you would do it (well, one way) in a native C/C++ application (or even in VB6 and below by declaring the SendMessage API.
You'll need the HWND to the destination window, but it sounds like you already have it. You'll also most likely need to register your service either as a specific user with local login rights, or as the Local System with the "Allow service to interact with desktop" checked (search this message board using "Search comments" above for a previous reply about how to do this I wrote a day or two ago).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I would like to know how to capture data coming from a RFID Reader. The RFID reader can be connected to a computer. But what kind of data will I get from the serial port or the USB port.
If the data is some kind of HEX, then I could write a module to convert the data to ASCII. But I am really not sure what kind of Data will be there. All i will have is the driver supplied by the manufacturer.
Is there any kind of source code or tutorial which can show how data is captured from a serial or a USB Port?
Regards,
Tarakeshwar
CCIE Q(Routing and Switching), MCSE Security
|
|
|
|
|
Tarakeshwar wrote:
If the data is some kind of HEX
Would that not imply that it was a binary stream? Isn't HEX normally used to display binary data to the developer via a debugger or whatnot?
Tarakeshwar wrote:
All i will have is the driver supplied by the manufacturer.
Is there any kind of source code or tutorial which can show how data is captured from a serial or a USB Port?
I would guess that the driver gets the data from the USB or serial port, your program will then have to communicate with the driver. Surely the manufacturer's documentation will explain this? If not then I'd suggest having a look at their website, or calling their technical support and getting the information from them.
|
|
|
|
|
You need to read the developer documentation for the RFID reader you have. The APIs for that reader will most likely be different than any other reader. This is true for many devices, from scientific instruments to meteorlogical instruments, etc. There is no standard communication protocol for such specific devices.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
<br />
private string update_http()<br />
{<br />
byte[] buf = new byte[80];<br />
HttpWebRequest request = (HttpWebRequest)WebRequest.Create<br />
("http://wheeloftime.net/ever_lstmsg.php");<br />
<br />
HttpWebResponse response = (HttpWebResponse)request.GetResponse();<br />
Stream resStream = response.GetResponseStream();<br />
<br />
int count = resStream.Read(buf, 0, buf.Length);<br />
<br />
msg = Encoding.UTF8.GetString(buf,0,buf.Length);<br />
<br />
resStream.Close(); <br />
Console.WriteLine(msg);<br />
return msg;<br />
}<br />
in the above code i keep getting "Hello Loren||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||"
returned instead of just "Hello Loren"
it is returning those pipe symbols to fill the rest of the buffer and using console.writeline doesn't show them only when i display it using DirectX 9.0
surface.DrawText(0,0,update_http(),true);
onto a surface
please help me remove the | charactors somehow thank you
|
|
|
|
|
|
Also, don't assume that the response is UTF-8-encoded. Use Encoding.GetEncoding , passing in the HttpWebResponse.ContentEncoding property, or default to UTF8 (a good default since printable ASCII is supported).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
how to make an application like jetaudio5, winamp5 and wmp9 appearance?
|
|
|
|
|
|
Hi:
Trying to know more about C# and its libraries ...
Without using explicit iterations, how could I:
1) Determine if a character is in a list of characters? For example if I want to know if the content of variable v is in a list containg 'a','j','1','%'. I normally do: if (v[i] == 'a' || v[i] == 'j' ..... but it is too long if I use with many characters in the list. I would like something like (if a[i] in ('a','j','1','%')) for example.
2) For writing the character ',' 600 times I would like to do this:
write(600(',')), for example and not use for statement.
Seems to be disheveled but .... May there may be alternatives.
Best regards
|
|
|
|
|
It worked.
I only changed IndexOfAny by IndexOf
Thanks for opening my eyes and ... my mind.
Best regards.
|
|
|
|
|
Hi all,
I need some major clarification on the thread locking mechanism. This might be a bit long so please bear with me.
Supposing we have a class definition as follows:
Class X
{
private Y obj1;
private Z obj2;
public void Ftn1()
{
lock (this) // section 1
{
obj1.ModifyThis();
}
}
public void Ftn2()
{
lock (obj2) // section 2
{
obj2.ModifyMe();
}
}
public void Ftn3()
{
lock (this) // section 3
{
obj2.ModifyMe();
}
}
}
// main ftn.
X mainObj;
Thread A new ThreadStart(mainObj.Ftn1());
Thread B new ThreadStart(mainObj.Ftn2());
Thread C new ThreadStart(mainObj.Ftn3());
// start them all now
My question are:
Q1. Since Ftn1 has a 'lock(this)' code block, if thread 'A' started first,
will 'B' and 'C' have to wait till 'A' is done (even though their jobs are to do ftn2 and ftn3. I ask this because, 'X' has been explicitly locked in the call to 'Ftn1', and 'Ftn2' and 'Ftn3' belong to this 'X'?
Note: My current understanding is that the 'lock(this)' call is actually only locking that section of code i.e. only this method is locked, but the 'this' now has me confused and I need it cleared up before I proceed any further.
Q2. If you look at Ftn2 and Ftn3, they lock different things, but acces the same resource, so my question is if Ftn2 fires first, then will all go well i.e. Ftn3 will have to wait till the lock on obj2 is released, but if ftn3 fires first, there is a possibility that obj2 will get a corrupted result but deadlock will never occur?
If my assumptions are true then I can continue on with endless coding more satisfied and releived.
Any other input or advice will also be very welcome. Thanks for reading.
|
|
|
|
|
Answer to Q1:
Fcn1 and Fcn3 will be synchronized, because they both lock "this", only one of them can go on at a time. Fcn2 will execute regardless what happens in Fcn1 and Fcn3, because it is locking a different object (obj2).
Answer to Q2:
Fcn2 and Fcn3 can execute concurrently, since they are modifying the same object, the code will not be thread-safe.
In general, if two blocks of code are locking the same object, then only one of them can be executed, the other will wait its turn. If they are locking different objects, even if one of the objects being locked is a member of the other object, the two blocks of code can execute concurrently.
Hope this helps.
My articles and software tools
|
|
|
|
|
This definitely helps, thank so much. But then how can I ever do the following:
If say a class 'Service' offers three services:
Class Service
{
void Service1()
{
// modify x
}
void Service 2()
{
// modify y
}
void Service3()
{
// modify z
}
}
and I there are 'n' number of threads, each wanting to do only 1 of these services. I want the ability to be able to only do 'method' locks, not lock the whole object meaning that services should be able to run simultaneously, becuase I know that these services modify different resources. No 2 thread should be able to enter the same service. C# only provides for
lock(...)
{
}
there is no syntax like
lock // this block of code
{
}
or is there?
Thanks again.
|
|
|
|
|
link_79 wrote:
No 2 thread should be able to enter the same service
link_79 wrote:
I know that these services modify different resources
In each method, just lock the variables modified in that method, this way, each method is somehow locked separately and services will run simultaneously.
I lock my house, I lock my car and I pull that zipper on my pants up several times a day, just for the sake of security.
|
|
|
|
|
link_79 wrote:
Class Service
{
void Service1()
{
// modify x
}
void Service 2()
{
// modify y
}
void Service3()
{
// modify z
}
}
A simple solution is:
Class Service
{
void Service1()
{
lock(x)
{
}
}
void Service 2()
{
lock(y)
{
}
}
void Service3()
{
lock(z)
{
}
}
}
When I say "lock" a block of code, I meant
lock(TheObjectToBeLocked)
{
// block of code
}
My articles and software tools
|
|
|
|
|
Geez, that solution was staring me in the face, but my internal bulb never went off. My doubts with the 'lock(this)', threw me off course. Thanks for all the help guys.
|
|
|
|
|
link_79 wrote:
Since Ftn1 has a 'lock(this)' code block, if thread 'A' started first,
will 'B' and 'C' have to wait till 'A' is done
Yes they have, because all the instance have been Locked.
|
|
|
|
|
Hi all
I'm trying ing to create usercontrols dynamically and add them into a placeholder. During a postback i got the following error
" Failed to load viewstate. The control tree into which viewstate is being loaded must match the control tree that was used to save viewstate during the previous request. For example, when adding controls dynamically, the controls added during a post-back must match the type and position of the controls added during the initial request. "
Is there any way I can solve this problem?
|
|
|
|
|
This question should be asked in the ASP.NET forum[^]. This forum is for questions specific for the C# language.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
i had a question i've been wondering about... when using winforms, you have to access controls on the same thread that owns that control, so from another thread you have to create a new delegate and call it via Invoke(), which marshals the call to the owning thread and works fine. my concern is the creation of the new delegate every time you call Invoke(). if I am calling Invoke very often, then the new delegate you have to create and pass to it would be rather inefficient, right? because when i do call Invoke, in my case i do know which function i want to be called at compile time, and it seems more efficient to create the delegate once, and pass that same object to Invoke everytime it's called. however, when trying to create a delegate like so:
public void delegate handler();
handler delegate_handler = new handler(myFunc);
i get some compile time error about not being able to reference non-static stuff.
any comments or suggestions?
|
|
|
|
|
You don't need to create the delegate each time. If you're invoking the same method over and over again, create the delegate once and keep a reference to it. It's merely a managed method pointer.
You can create a delegate that references both static and instance methods, but you have to include either the class name or the object reference with the method, just as if you were going to call the method without using a delegate (and the same rules for methods defined on the executing class are the same as well).
So, lets say you want to set the text for a TextBox from another thread and you expect to do it quite a bit. Do something like this:
private delegate void SetValueDelegate(object obj, object value,
object[] index);
private SetValueDelegate _setValueDelegate;
public void SafeSetText(TextBox tb, string value)
{
if (tb == null) throw new ArgumentNullException("tb");
if (tb.InvokeRequired)
{
if (_setValueDelegate== null)
{
PropertyInfo pi = tb.GetType().GetProperty("Text");
_setValueDelegate= new SetValueDelegate(pi.SetValue);
}
tb.Invoke(_setValueDelegate, new object[] {tb, value, null});
}
else tb.Text = value;
} This is just a sample, of course, but notice how I create a delegate that references an instance method using pi.SetValue . Even though the delegate isn't referencing a method on the control (that's much easier; with getting/setting properties you have to use reflection or the component model), the delegate is still invoked in the control's thread in which it was created.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|