|
Hi Luc,
The second method (checkProblematicValves) does contain an InvokeRequired/Invoke construct<br />
which is intended to make it execute again on the thread that created valveCheckedListBox,<br />
so yes this method may execute twice.
I don't understand how exactly, Invoke() works, you got me confused.
Can you please explain to me how exactly it works, what do you mean by:
<br />
causing the ENTIRE method to run again
Is the following code what you meant???
private void checkProblematicValves()
{
if (valveCheckedListBox.InvokeRequired)
{
checkProblematicValvesHendler d = new checkProblematicValvesHendler(checkProblematicValves);
valveCheckedListBox.Invoke(d);
}
else
{
foreach (long key in messageArr.Keys)
{
if (messageArr[key] != null)
{
foreach (object message in messageArr[key])
{
if (message is Clusters.CSensorStatus)
{
if ((message as Clusters.CSensorStatus).valveAngDeg > 0 )
{
string myKey = LongToHex(key);
int index = valveCheckedListBox.Items.IndexOf(myKey);
valveCheckedListBox.SetItemChecked(index, true);
}
}
}
}
}
}
}
|
|
|
|
|
Hi,
I have not checked all the details, but it looks pretty close, yes.
How did you come to use InvokeRequired/Invoke without really understanding it?
I suggest you read some documentation on it if you feel the need to know more.
BTW: there is one optimization you might consider; if chances are nothing needs to be done,
then there is no need to do the Invoke stuff, so you might want to duplicate the looping
stuff in front of everything and rather than invoking itself or calling SetItemChecked, just
set a bool to true to indicate the existing code should be executed.
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- use PRE tags to preserve formatting when showing multi-line code snippets
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
I do not understand what you meant to tell me.
I am supposed to check each and every object in the messageArr List<object> for the certain condition
and if it is true, I have to check the relevant Item in the CheckedListBox.
therefor the code must be executed any way for the best of my knowledge.
Is there something I am missing here?
do you see a situation where nothing needs to be done?
please enlighten me and tell me of which situation you speak.
how am I supposed to check the Item without calling Invoke?
|
|
|
|
|
Hi,
1.
your code seems OK.
I trust you have it working?
2.
what I meant to tell you was maybe your code runs even at times that there are
no messages, or all tests (valveAngDeg > 0) will fail, so nothing needs to be changed
in the GUI. If so, there was no need to let the GUI thread execute the function,
so if that is relevant you could do something like this (in pseudo-code):
void checkProblematicValvesNew() {
bool GuiChangeNeeded=false;
foreach(thing to be checked) {
if (GUI indeed needs a change) GuiChangeNeeded=true;
}
if (GuiChangeNeeded) {
checkProblematicValves();
}
}
but probably it is not really worth the effort...
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- use PRE tags to preserve formatting when showing multi-line code snippets
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Hi guys,
Anybody knows how to work with the currently opened IM chat sessions (both msn and yahoo)? I need to develop a windows application, most probably in C# or VC, in which the messages coming in and out from the IM sessions need to be grabbed and recorded. This is required to be done in the backend. Please help me if anybody has worked on such or similar thing before.
Reference to any article or site which helps in this connection will also be appreciated.
Thankyou,
bABURmAN
|
|
|
|
|
|
Lots of Thanks Abhijit. These are good examples of getting the status or text etc. I just went through them but didn't yet run them on my machine. I hope they will run ok but here i need to control like
1- if a user can start IM session,
2- a use can send/receive files,
3- a user can have a chat session with certain user(s).
Similarly i need to have a log of how much time a session was continued etc. Is it possible through this interface?
bABURmAN
|
|
|
|
|
Basically, you have three choices:
1) write a network packet sniffer and capture the packets that are necessary for you
2) use the official APIs of these messengers, if available
3) using some P/Invoke you can find the message windows using FindWindow(Ex) and grab the text using WM_GETTEXT or other techniques
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Hi Greeeg,
Could u kindly explain in details ???
Thanks in advance !!!
Happy Programming
-----
Abhijit
|
|
|
|
|
hi ,
in this code i dont want to declare the result as a static gloabl variable..why are doing so and how can i avoid doing that...
class Program
{
static int result;
public int add(int x,int y)
{
result = x+y;
return result;
}
static void Main(string[] args)
{
Program obj = new Program();
int sum = obj.add(10, 20);
Console.WriteLine("{0}", result);
Console.WriteLine("{0}", sum);
Console.ReadLine();
}
}
}
thanks
C#
|
|
|
|
|
I thing from the output of your code you will get your ans
Happy Programming
-----
Abhijit
|
|
|
|
|
am sorry but i didnot understand what u said abhijith
am a beginner and can u explain tis to me plzz
thansk
C#
|
|
|
|
|
just replace add method with
public int add(int x,int y)
{
return x+y;
}
And remove the global variable result from the code
|
|
|
|
|
Hi,
your program does not need result to be static. It is used by add() only,
which is not static, so it could access instance members.
But your class does not need a data field result at all. It is used only inside add(), so make
it a variable local to add().
BTW: once you fixed that, the add() method no longer uses any class members, so you
COULD declare it static to make that clear.
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- use PRE tags to preserve formatting when showing multi-line code snippets
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
hi
I would like to know how can i customize the rules for fxcop
thanks
bhaskarsri
Bhaskarsri
|
|
|
|
|
Depends on what you want to do. You can't change the rules that ship with FxCop, but you can write your own rules that are added to it.
|
|
|
|
|
hi
I would like to add my own rules. i would like to know from you that how can i add my own rules to the existing fxcop.
thanks
bhaskarsri
Bhaskarsri
|
|
|
|
|
|
i want to create setup package for my application c#2005 windows application
i need to check if there sql server engine on the machine the setup package doesn't setup it
if not setup it and the same for .net framework
i need this answer very very quickly
thanks
md_refay
|
|
|
|
|
md_refay wrote: i need this answer very very quickly
I need $1,000,000 very very quickly.
You always pass failure on the way to success.
|
|
|
|
|
|
Will this[^] article help?
/ravi
|
|
|
|
|
But, This will not fulfill his all requirment !!!!
His main concern with Prerequisitics of .net framework and SQL Server engine !!!!!
Happy Programming
-----
Abhijit
|
|
|
|
|
I thought this[^] note would enable the developer to specify a dependency on the .NET framework and SQL server.
/ravi
|
|
|
|
|
yup, that i already provide him.
Happy Programming
-----
Abhijit
|
|
|
|