|
jschell wrote: there is no way to ensure that an action in thread 1 will only occur at point x in thread 2
What do you mean? That's what Monitors, Mutexes, (Manual/Auto)ResetEvents, etc. are for. The other example I posted demonstrates this using lock s. Inside the receive callback the thread waits on the state object until no other thread is in a critical section using the socket. Likewise the Close method waits on the same object until all other threads have left their critical sections that use the socket.
|
|
|
|
|
Dear Sirs,
I'm having a problem with SetWindowsHookEx. In Debug mode, no problem, in release, it throws. Here's the code:
namespace barcode
{
public static class program
{
static void Main(string[] args)
{
_keyboard_delegate = Keyboard_Msg_Pump;
_keyboard_hook_handle = SetWindowsHookEx(
WH_KEYBOARD_LL,
_keyboard_delegate,
System.Runtime.InteropServices.Marshal.GetHINSTANCE(
System.Reflection.Assembly.GetExecutingAssembly().GetModules()[0]),
0);
if (_keyboard_hook_handle == 0)
{
int errorCode = System.Runtime.InteropServices.Marshal.GetLastWin32Error();
throw new System.ComponentModel.Win32Exception(errorCode);
}
}
private static int Keyboard_Msg_Pump(int nCode, System.Int32 wParam, System.IntPtr lParam)
{
return 12;
}
private static int _keyboard_hook_handle;
private static HOOKPROC _keyboard_delegate;
private delegate int HOOKPROC(int nCode, int wParam, System.IntPtr lParam);
private const int WH_KEYBOARD_LL = 13;
[System.Runtime.InteropServices.DllImport("user32.dll",
CharSet=System.Runtime.InteropServices.CharSet.Auto,
CallingConvention=System.Runtime.InteropServices.CallingConvention.StdCall,
SetLastError=true)]
private static extern int SetWindowsHookEx(
int idHook,
HOOKPROC lpfn,
System.IntPtr hMod,
int dwThreadId);
}
}
If you get to line sixteen (right after the if statement in the Main proc), you have an error. Try stepping through this example and tell me if it works for you. If I'm in debug mode, it works for me, but if I'm in release (even with optimize code off, which I thought would make it just like DEBUG), it fails with inconsistent errors, sometimes it says "Operation completed successfully" sometimes it says "Access denied" and other things. Let me know if you can run it in Release, and how. If not, tell me what error you get.
JUST NOW, as I was writing this, I decided that it might be the setting, "Enable the VSHost" process. If it's off, it works. If it's on, no good. Does the VSHost run under lower authority than the user?? Let me know what you think.
In Christ,
Aaron Laws
http://ProCure.com
|
|
|
|
|
Yep, in order for the keyboard hook to work, you have to turn off the VS Hosting process. I don't know why - you just do. I also don't have any documentation on this. I'm just speaking from my own experience.
|
|
|
|
|
Hi , have a good day
Can anyone Explain for me what the meaning of this ?
a = b == null ? null : a.ToString();
P.S : for more information :
I use this component Example Code , and I need to understand it !
http://www.gemboxsoftware.com/help/html/M_GemBox_Spreadsheet_ExcelWorksheet_ExtractToDataTable.htm[^]
if (e.ErrorID == ExtractDataError.WrongType)
{
e.DataTableValue = e.ExcelValue == null ? null : e.ExcelValue.ToString();
e.Action = ExtractDataEventAction.Continue;
}
Please , Don't tell to Ask at Component Forum , due my question is C# syntax things
thank you
I know nothing , I know nothing ...
|
|
|
|
|
It means
if (b == null)
a = null;
else
a = a.ToString();
But it's an expression instead of a statement.
|
|
|
|
|
Thank you so much , for this fast , great replay of yours ,
you saved me from headache
I have voted for you
I know nothing , I know nothing ...
|
|
|
|
|
Thanks
|
|
|
|
|
And yes I meant b.toString();
I know nothing , I know nothing ...
|
|
|
|
|
everything you should know about C# is in your C# book, in MSDN, in the C# specification[^], etc.
|
|
|
|
|
Thank you ,
But for a certain things MSDN is Yak !
http://msdn.microsoft.com/en-us/library/ty67wk28.aspx[^]
The conditional operator is right-associative. The expression a ? b : c ? d : e is evaluated as a ? b : (c ? d : e), not as (a ? b : c) ? d : e.<br />
<br />
The conditional operator cannot be overloaded.
I know nothing , I know nothing ...
|
|
|
|
|
You're right, and that's classic Microsoft - technically accurate, entirely useless information!
"A Journey of a Thousand Rest Stops Begins with a Single Movement"
|
|
|
|
|
"you're in an airplane" kind of stuff?
|
|
|
|
|
Exactly!
"A Journey of a Thousand Rest Stops Begins with a Single Movement"
|
|
|
|
|
Where is the Yak point? In all fairness, the first line of the document states;
The conditional operator (?:) returns one of two values depending on the value of a Boolean expression.
Perfect logical KISS.
I are Troll
|
|
|
|
|
I do not understand why you think like that.
|
|
|
|
|
I guess you meant b.ToString there. If you did, you really don't need ternary operator. Convert.ToString would be enough.
|
|
|
|
|
a = b == null ? null : a.ToString();
Means if b equals null then set a = null
else set a = a.ToString()
if code changed to following, I may understand it.
if (b == null)
{
a = null;
}
else
{
a = a.toString()
}
|
|
|
|
|
? operator its like a IF-result statement.
look:
int x = 0;
int y = 1;
if(x > y) ? y++ : y--;
If x>y = true, y++.
If x>y = false, y--;
|
|
|
|
|
I am using FFMPEG for streaming operations.
(https://www.transferbigfiles.com/a3209f95-ffcc-4c82-b722-041a24c26ec1?rid=KsWHbP3Lo/rxGH4YHVVVtA%3d%3d)
I started it using the following program
Process myProcess = new Process();
myProcess.StartInfo.FileName = @"ffmpeg.exe";
myProcess.StartInfo.UseShellExecute = false;
myProcess.StartInfo.RedirectStandardInput = true;
myProcess.StartInfo.Arguments = "-i input.avi -vcodec copy -acodec copy output.avi";
myProcess.Start();
StreamWriter myStreamWriter = myProcess.StandardInput;
myStreamWriter.Write("113");
myStreamWriter.Flush();
myStreamWriter.Write('q');
myStreamWriter.Flush();
myStreamWriter.Close();
myProcess.WaitForExit();
myProcess.Close();
My intention is to close the program when I send "q" from the program (I meant a graceful exit without making any error).
But I can't close it by sending 'q' character or its corresponding ascii. When I run the program from the command line and I press q in the keyboard, program immediately gets closed.
Can you pls. help me?
Thank you
regards
anvesh
|
|
|
|
|
|
Thanx for the reply,
Its actually a nice article. But I couldn't solve my issue using it.
A carriage return is not necessary for this application to close. Pressing a 'q' itself (from keyboard) will give give graceful end to the program. I need not press an additional enter key.
And as an additional step of precaution, I made my own console program which requries a 'q' followed by carriage return to close the application, and it worked fine when I use WriteLine from .NET
What might be the issue? Its only for ffmpeg that I can't send input stream to. I am anxious to know what might be the issue?
|
|
|
|
|
I don't know, I'm stumped. But maybe the program reads something internal instead of the input stream.
What is ffmpeg? Maybe I can try it.
|
|
|
|
|
ffmpeg produces libraries and programs for handling multimedia. We can convert media files into different formats using ffmpeg. It can also record live streams from a camera in different formats.
I am attaching the ffmpeg.exe here.
https://www.transferbigfiles.com/a3209f95-ffcc-4c82-b722-041a24c26ec1?rid=KsWHbP3Lo/rxGH4YHVVVtA%3d%3d[^]
Here in my code i just copy the audio and video codecs of a file (input.avi) into another file(output.avi). Different parameters can be added in this command, but I just consider the basic operation here.
Process myProcess = new Process();
myProcess.StartInfo.FileName = @"ffmpeg.exe";
myProcess.StartInfo.UseShellExecute = false;
myProcess.StartInfo.RedirectStandardInput = true;
myProcess.StartInfo.Arguments = "-i input.avi -vcodec flv -acodec copy output.flv";
myProcess.Start();
StreamWriter myStreamWriter = myProcess.StandardInput;
myStreamWriter.Write("113");
myStreamWriter.Flush();
myStreamWriter.Write('q');
myStreamWriter.Flush();
myStreamWriter.Close();
myProcess.WaitForExit();
myProcess.Close()
;
If i run the pgm ( ffmpeg.exe should be placed in same foldr) it starts the conversion from avi to flv.
When I press [q] the pgm gets closed gracefully.
But I I am not being able to close it by sending 'q' character or its corresponding ascii.
|
|
|
|
|
anveshvm wrote: WriteLine
Oh, yeah, that may actually send a LINEFEED and a CARRIAGE-RETURN. If so, you would have to set the NewLine property.
|
|
|
|
|
Come to think of it, you may only need to add a CARRIAGE-RETURN character.
|
|
|
|