|
thanks dude!!
i'll try it "Filter on the DataGrid"!!
if i find out anything else i´ll call you again!!!
cya!
|
|
|
|
|
can i enter a command line argument after installing application from clickonce technology
|
|
|
|
|
A command line argument to the click once application? Yes, but you have to take some steps to allow command line arguments. When publishing the ClickOnce app from Visual Studio, go into your project settings page, Options, then enabled "Allow URL parameters to be passed to your application". You can then pass parameters via a query string:
www.myclickonceapp.com/theapp.application?someParam=5
|
|
|
|
|
Hi,
I'm currently in the process of planning a Server-Client application and evaluating whether Remoting is a good way to go. I've already read some MSDN articles about remoting and also looked at some of the remoting articles here but there are still some questions:
1. Is the server side knowing which clients are currently connected?
What I currently know is that connected clients can instaniate and fetch objects from the server. Calls on functions on those objects may either be run locally or on the serevr side. Is it possible to determine on the server side which clients currently hold those objects? I know I could define functions so that clients can explicitely notify their connection or disconnection but I think about lost connections or client side crahes where no explicit call is possible anymore.
2. Can the server send messages to the clients?
In the examples I have investigated so far (mostly chat apps) the clients regulary poll for new data from the server. Is there a possibility that the server directly calls functions in all connected clients?
3. When a client makes a call in the server does this call create server side a new thread in which this call is processed? Is this the same for every call coming from the same client?
Robert
|
|
|
|
|
Robert Rohde wrote: 2. Can the server send messages to the clients?
In the examples I have investigated so far (mostly chat apps) the clients regulary poll for new data from the server. Is there a possibility that the server directly calls functions in all connected clients?
Yes, in fact, you can use the normal event mechanism to do that i.e server exposes an event and clients subscribe to it. There are a few gotchas though, like firewalls preventing incoming traffic. You would also have to make some config changes to allow clients to recieve calls (See TypeFilterLevel[^]).
Robert Rohde wrote: 3. When a client makes a call in the server does this call create server side a new thread in which this call is processed? Is this the same for every call coming from the same client?
Last I checked, remoting calls come in on a IOCP Thread. The .NET ThreadPool has a 1000 of them by default, in addition to the normal 25 threads per processor.
|
|
|
|
|
|
|
Hello,
I have written an application in c# and would like to set a shortcut key to start the application.
I would like to use ctrl+shift+h to start the application.
Also I would like the user to be able to change this shortcut key.
Can anyone help.
Thanks
cjm
|
|
|
|
|
you need to use system wide hook so that the os can intercept any key strokes and determine if it matches the ones you want then you process them and fire the application.
then you need a shortcut editor to change the shortcut by listening to the keys the user enters and rather than opening the program, assign it as the hotkey.
below is a class i found and adapted to suit my needs ( the class didn't have any copyright info in it and i can't remember where i found it, so i apologize if anyone is offended, although i did modify and improve it extensively )
DO NOT USE THIS CODE FOR MALICIOUS ACTIVITY, ELSE I WILL BE *VERY* DISSAPOINTED, AND YOU MAY GO TO HELL FOR IT!
using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace GlobalKeyHook
{
public class KeyboardHook : IDisposable
{
#region Hook-dlls
[DllImport("user32", EntryPoint = "SetWindowsHookExA")]
private static extern int SetWindowsHookEx(int idHook, KeyBoardCatcherDelegate lpfn, int hmod, int dwThreadId);
[DllImport("user32.dll", CharSet = CharSet.Auto,
ExactSpelling = true, CallingConvention = CallingConvention.Winapi)]
private static extern short GetKeyState(int keyCode);
[DllImport("user32", EntryPoint = "MapVirtualKey")]
private static extern int MapVirtualKey(int wCode, int wMapType);
[DllImport("user32", EntryPoint = "CallNextHookEx")]
private static extern int CallNextHook(int hHook, int ncode, int wParam, KeybHookStruct lParam);
private const int
WH_KEYBOARD = 2,
WH_KEYBOARD_LL = 13;
[DllImport("user32", EntryPoint = "UnhookWindowsHookEx")]
private static extern int UnhookWindowsHookEx(int hHook);
#endregion
private bool m_DisableHooking = false;
public bool DisableHooking
{
get { return m_DisableHooking; }
set { m_DisableHooking = value; }
}
public KeyboardHook()
{
kbcatcher = new KeyBoardCatcherDelegate(KeyBoardCatcher);
keybhook = SetWindowsHookEx(WH_KEYBOARD_LL, kbcatcher,
Marshal.GetHINSTANCE(typeof(KeyboardHook).Module).ToInt32(), 0);
if (keybhook == 0)
throw new ExternalException("Error: " + Marshal.GetLastWin32Error().ToString() + "\r\nCould not hook keyboard");
}
public KeyboardHook(bool AddModifierData)
: this()
{
this.AddModifierData = AddModifierData;
}
#region Dispose
private readonly int keybhook;
private bool disposed;
public void Dispose()
{
if (!disposed)
{
UnhookWindowsHookEx(keybhook);
GC.SuppressFinalize(this);
disposed = true;
}
}
~KeyboardHook()
{
Dispose();
}
#endregion
private struct KeybHookStruct
{
public int vkCode, scanCode, flags, time, dwExtraInfo;
}
private delegate int KeyBoardCatcherDelegate(int code, int wparam, ref KeybHookStruct lparam);
public static bool CheckKeyPressed(params Keys[] keys)
{
for (int i = 0; i < keys.Length; i++)
if (!CheckKeyPressed(ref keys[i])) return false;
return true;
}
public static bool CheckKeyPressed(ref Keys key)
{
return CheckKeyPressed((int)key);
}
public static bool CheckKeyPressed(int vkey)
{
short ks = GetKeyState(vkey);
Console.WriteLine(ks);
return ks == 1;
}
public bool IsKeyPressed(Keys key)
{
return CheckKeyPressed(ref key);
}
public bool AreKeysPressed(params Keys[] keys)
{
return CheckKeyPressed(keys);
}
private const int HC_ACTION = 0;
[MarshalAs(UnmanagedType.FunctionPtr)]
private KeyBoardCatcherDelegate kbcatcher;
public event KeyEventHandler
KeyDown = null,
KeyUp = null;
private const int
wpKeyDown = 256,
wpKeyUp = 257;
public bool AddModifierData = true;
public readonly Keys[] Modifiers = { Keys.Alt, Keys.Control, Keys.Shift };
private int KeyBoardCatcher(int hookcode, int wparam, ref KeybHookStruct lparam)
{
if (HC_ACTION == hookcode)
{
if ((wparam == wpKeyDown && KeyDown != null)
|| (wparam == wpKeyUp && KeyUp != null))
{
try
{
Keys k = (Keys)lparam.vkCode;
if (AddModifierData)
k |= Control.ModifierKeys;
KeyEventArgs e = new KeyEventArgs(k);
if (wparam == wpKeyDown)
KeyDown(this, e);
else
KeyUp(this, e);
if (e.Handled) return 1;
}
catch { }
}
}
return CallNextHook(keybhook, hookcode, wparam, lparam);
}
}
}
in your main init it like this
KeyHooker keyhooker = KeyHooker.Instance;
when you want to disable it so you can process the keys in the 'key editor' or 'key assignor', do this
KeyHooker.Instance.DisableHooking = true;
then re-enable them on form close or after the hot key is decided with this
KeyHooker.Instance.DisableHooking = false;
hope that helps
g00fy
|
|
|
|
|
cheers dude. thats a lot of code but I will give it a go.
atb
cjm
|
|
|
|
|
hi,
i'm doing a windows service and i want the service to take a screen shot
every (time unit)....
is there any ready component for this.. or is this possible?
|
|
|
|
|
a little util class i wrote some time ago
using System;
using System.Drawing;
using System.Runtime.InteropServices;
namespace ScreenShot.interop
{
public sealed class Desktop
{
[DllImport("user32.dll")]
internal extern static IntPtr GetDesktopWindow();
[DllImport("user32.dll")]
internal extern static IntPtr GetDC(IntPtr windowHandle);
[DllImport("gdi32.dll")]
internal extern static IntPtr GetCurrentObject(IntPtr hdc, ushort objectType);
[DllImport("user32.dll")]
internal extern static void ReleaseDC(IntPtr hdc);
[DllImport("user32.dll")]
internal extern static void UpdateWindow(IntPtr hwnd);
[DllImport("user32")]
internal static extern IntPtr GetWindowDC(IntPtr hwnd);
[DllImport("user32")]
public static extern IntPtr GetForegroundWindow();
internal static Bitmap Capture()
{
try
{
IntPtr desktopWindow = GetDesktopWindow();
IntPtr desktopDC = GetDC(desktopWindow);
Bitmap desktopImage = GetBitmap(desktopDC);
ReleaseDC(desktopDC);
return desktopImage;
}
catch (Exception e)
{
ScreenShotConfig.persistance.Logger.Log(typeof(Desktop), "Capture(): " + e.Message);
return null;
}
}
internal static Bitmap GetBitmap(IntPtr imagePtr)
{
IntPtr hwnd = GetCurrentObject(imagePtr, 7);
Bitmap desktopImage = Image.FromHbitmap(hwnd);
return desktopImage;
}
internal static Bitmap GetForegroundWindowBitmap()
{
IntPtr handle = GetForegroundWindow();
IntPtr windowDC = GetWindowDC(handle);
IntPtr hwnd = GetCurrentObject(windowDC, 0);
Bitmap desktopImage = Image.FromHbitmap(hwnd);
ReleaseDC(windowDC);
return desktopImage;
}
}
}
call it with
Bitmap b = Desktop.Capture();
hope that helps
g00fy
|
|
|
|
|
I don't do a lot of this, but is there any reason you couldn't just:
Rectangle rec = Screen.PrimaryScreen.Bounds;
Bitmap screenCap = new Bitmap(rec.Width, rec.Height, PixelFormat.Format32bppArgb);
Graphics getScreen = Graphics.FromImage(screenCap);
getScreen.CopyFromScreen(rec.X, rec.Y, 0, 0, rec.Size, CopyPixelOperation.SourceCopy);
return screenCap;
--EricDV Sig---------
Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them.
- Laurence J. Peters
|
|
|
|
|
No it didn't worked. It's creating blank screen. It's problem when we call from inside of Windows Service.
|
|
|
|
|
I have a question.
Right now i have made a server. It works just fine but there is a problem.
I need to push a button in order to recieve data. I would like suggestions (and examples)
how i can create a server wich regularly (always?) listens if data is sendt.
Can anyone help me with this?
|
|
|
|
|
In generally you solve this problem by using loops. Make a button "Start listening" which sets a bool variable, lets call it KeepListening, to true and call the listenfunction which contains a loop like
while (KeepListening)
{
// Put Receive-Code in here...
System.Threading.Thread.Sleep(10);
}
Now the second button sets the variable KeepListening to false. If you click it, the application will leave the loop.
If you want to make your application listen to incoming traffic and also being available for user inputs, you will have to use threads (create a listening thread).
There are nice threading-tutorials out there if you aren't familiar with threading at all. I'm too lazy/busy to search for a nice explanation but i will do if you are not successful.
Lets sum it up:
- You will have to use a Loop to listen all the time.
- You will have to make use of the multithreading if your application should be available for other tasks while listening.
Good luck,
mik
|
|
|
|
|
Yo Mik,
Tnx a lot for you're answer. I have read some tuts on threading but they are not really clear to me. If u have time and u know one please tell me . I'm not in a big hurry so ......
Again tnx.
|
|
|
|
|
okay, lets create a simple listening function and the eventhandlers for those buttons
<br />
bool KeepListening = false;<br />
<br />
public void button_StartListen_click(object sender, EventArgs e)<br />
{<br />
KeepListening = true;<br />
System.Threading.Thread myListenThread = new System.Threading.Tread(new System.Threading.ThreadStart(Listen));<br />
myListenThread.Start();<br />
}<br />
<br />
public void button_StopListen_click(object sender, EventArgs e)<br />
{<br />
KeepListening = false;<br />
}<br />
<br />
private void Listen()<br />
{<br />
while (KeepListening)<br />
{<br />
System.Threading.Thread.Sleep(10);<br />
}<br />
}<br />
Okay, thats how it could look like now lets see what exactly happens here.
If you click on the "Start Listening" Button, the method button_StartListen_Click is called and:
- Sets KeepListening to 'true'
- Initiates a new object of the Thread Class and pass one argument in its constructor.
- Starts the new Thread.
Now the thread is running in the background. The threads task is to call the method "Listen" with no arguments. When doing so the method won't exit until you click the "Stop Listening" button because of the loop.
If you click the "Stop Listening" button now the button_StopListen_Click method will:
- Sets KeepListening to 'false'
Setting the KeepListening variable to false will cause the loop condition (while (KeepListening)) to be not forfilled. This makes the method exit and the thread will do so too!
This is no explanation about threading since this is a very complex subject. You should start playing around with them because multithreading is what you want your application to do ;D
However, hope you understood what i was talking about - if the code example does not work i will start my ide and create a working example
|
|
|
|
|
Yo Mik ,
Its working perfect the only small problem i got left is when i want to add the recieved stuff to a listbox i get the following error :
Additional information: Cross-thread operation not valid: Control 'lbReceived' accessed from a thread other than the thread it was created on.
Any idea how i can fix this ?
Greetings ,
Jacco
|
|
|
|
|
hehe this is where it gets complicated. i haven't done much with threads at all but i also came across this problem when writing a "popup" class. as you may have noticed you were starting another thread for the listening method. the thread where all the controls remain to is the one where you started the second thread from. sounds complicated but it isn't.
now you have to communicate from one thread to another. you can do this by using the invoke procedure of the control. i just will give you the sourcecode and you will see what will happen
instead of using the regular add method of the listbox you have to use the listboxs "invoke" method.
Put this code somewhere inside your class:
<br />
private delegate void AddTextInvoker(string textToAdd);<br />
Now replace the line of code where you want to add an item to the listbox with these lines:
<br />
object [] invokeParams = {"TextOrItemToAdd"};<br />
lbReceived.Invoke(new AddTextInvoker(AddTextToListbox), invokeParams);<br />
finally add the "AddTextToListbox" method to your class and make it add an item to the listbox:
<br />
private void AddTextToListbox(string textToAdd)<br />
{<br />
lbReceived.Add(textToAdd);<br />
}<br />
but be careful with invoking anything. it happened to me that one thread disposed a control and another one tried to change on of its properties - that will result in an exception. you should try to make yourself more familiar with threads since my knowledge ends here too. maybe someone else could tell you WHY its not possible to do a cross-thread operation and stuff - for now you should be able to solve your problem :P
// edit: sorry code snippet did not work because it just was wrong - now it should work :P
-- modified at 9:00 Tuesday 10th October, 2006
|
|
|
|
|
What will be the effect on the performence of the Operating System, when the garbage collector is periodically called (GC.collect()) ?
Mandar Kulkarni
|
|
|
|
|
The garbage collector wont affect the Operating system. It may affect a little with a slow processor but with fast processors it wont affect.
By the way u don't need to call the Garbage collector cause it is been called automatically when the processor has enough time to do that work.
Jamil Abou Khalil
|
|
|
|
|
The Garbage Collector runs on a per process basis, so the worst it can do to the OS is what a badly behaving program can do. Why do you want to explicitly call GC.Collect ? I'm sure you know that the GC runs automatically whenever it senses memory pressure and explicitly calling GC.Collect is not going to free any more objects than the next GC cycle is going to collect.
|
|
|
|
|
Hello
i have a simple windows form with a TabControl and several TabPages. I've added Event Handlers for the TabPage's Enter/Leave/Validating events.
The Events never fire! The same code build with VS2005 works!
How can i get the Events to work with VS2003 and .Net 1.1 ?
Michael
|
|
|
|
|
You have to be aware that VS 2005 differs a lot from the old ones. Unlike the VS2003 and .Net 1.1 that are much similar to each other. In VS2005 many of the namespaces have changed and many were combined with some other and many new where added.U can't expect for the same coding to work for VS2005 and VS2003.
Maybe this is not the case. Maybe you are not fire the events. If you are just copy and pate the source code then you wouldn't be initalizing the events. You should go to each tab seperatly and fire the events.
Hope it will benefit you.
Jamil abou khalil
|
|
|
|