Click here to Skip to main content

Comments by Grasshopper.iics (Top 12 by date)

Grasshopper.iics at 22-Jan-13 11:27am View
If you are using Digital Persona, then it comes with a driver. Every driver puts a registry entry. There are some simple Win API method which can detect when a USB device is inserted. You can compare the device ID and use some password to activate the device. However if a hardware lock is so important, cant there be a USB hub? Logic remains same. Alongside the device you provide a USB stick and embed it's ID into program for password checking. However if such a solution needs to be distributed in lot then software lock might be best option?
Grasshopper.iics at 21-Jan-13 20:47pm View
You have set SeriesChartType.Point, it should be SeriesChartType.Column
Grasshopper.iics at 21-Jan-13 18:53pm View
BeginInvoke by UI controls or thread is meant to be executed at the background. So When you have loads of statement and use BeginInvoke at the end, UI gets updated smoothly. Do a simple test. Take a Label, and a button. on click event write the following code. for (int i = 0; i < 100; i++) { this.BeginInvoke((MethodInvoker)delegate { label1.Text = i.ToString(); System.Threading.Thread.Sleep(100); // your UI update code here. e.g. this.Close();Label1.Text="something"; }); } // System.Threading.Thread.Sleep(2000); MessageBox.Show("Done"); Dont you see your UI in wait state? That is what I mean. In his code context, calling BeginInvoke from inside nested loops is not executing asynchronously. First Invoke is locking the resource, the second call is waiting for that to complete. So even though they are executing asynchronously, lock is not managed that way.
Grasshopper.iics at 21-Jan-13 18:33pm View
Put argument to rest, please check with the suggested changes first!
Grasshopper.iics at 21-Jan-13 3:17am View
I am sorry, but I really don't get you here SA. I considered member to be relatively new in coding as he seems to be relatively new to cp. So I offered an easy way out. You voted me 1, stamping the answer not suitable. I pulled out some work from another project which I found some times back in stackoverflow. This solution works best, no matter what your file type is. But you are now saying that the solution is complicated. By the mean time OP has not come back to comment on any solutions or clarifying any point. Should we consider 1. To check if a file is locked, my first solution 2. To find the exact process and the name with file handle, my second method. Where I used it? I have controlled power point slide through some stuff like lasser , voice, hand movement, eye blink. I use this technique to find out the Handle (Int32 pointer to process) and then I pass the keys through Sendkey(). So please clarify if I am wrong in my either cases.
Grasshopper.iics at 21-Jan-13 1:54am View
This works fine under Windows 7, does not require to open another process ( handle.exe). All you be doing is using GetProcessesLockingFile() method. Solution to Non trivial problems can not be trivial. Even handle.exe shoots up loads of problems !
Grasshopper.iics at 21-Jan-13 1:33am View
As par your question, it was meant to be "if a file is being used by another process". Do let me understand if your question suggest anything in particular which is not answered? Say if you needed an information about "which process is currently accessing a file?" If you had, I would have given you following solution which will display the process that is actually holding your file access ( Somethimes back I had done similar stuff, ref using System; using System.Collections.Generic; using System.Runtime.InteropServices; using System.Diagnostics; using System.Text; using System.Threading; namespace FileLockInfo { public class Win32Processes { /// /// Return a list of processes that hold on the given file. /// /// static void Main() { Console.WriteLine("C:\\Users\\Rupam\\Desktop\\Transaction Details.pdf"); GetProcessesLockingFile("C:\\Users\\Rupam\\Desktop\\Transaction Details - PayPal.pdf"); Console.Read(); } public static List<Process> GetProcessesLockingFile(string filePath) { var procs = new List<Process>(); var processListSnapshot = Process.GetProcesses(); foreach (var process in processListSnapshot) { Console.WriteLine( process.ProcessName); if (process.Id <= 4) { continue; } // system processes var files = GetFilesLockedBy(process); if (files.Contains(filePath)) { Console.WriteLine("--------------->"+process.ProcessName); procs.Add(process); } } return procs; } /// /// Return a list of file locks held by the process. /// public static List GetFilesLockedBy(Process process) { var outp = new List(); ThreadStart ts = delegate { try { outp = UnsafeGetFilesLockedBy(process); } catch { Ignore(); } }; try { var t = new Thread(ts); t.IsBackground = true; t.Start(); if (!t.Join(250)) { try { t.Interrupt(); t.Abort(); } catch { Ignore(); } } } catch { Ignore(); } return outp; } #region Inner Workings private static void Ignore() { } private static List UnsafeGetFilesLockedBy(Process process) { try { var handles = GetHandles(process); var files = new List(); foreach (var handle in handles) { var file = GetFilePath(handle, process); if (file != null) files.Add(file); } return files; } catch { return new List(); } } const int CNST_SYSTEM_HANDLE_INFORMATION = 16; private static string GetFilePath(Win32API.SYSTEM_HANDLE_INFORMATION systemHandleInformation, Process process) { var ipProcessHwnd = Win32API.OpenProcess(Win32API.ProcessAccessFlags.All, false, process.Id); var objBasic = new Win32API.OBJECT_BASIC_INFORMATION(); var objObjectType = new Win32API.OBJECT_TYPE_INFORMATION(); var objObjectName = new Win32API.OBJECT_NAME_INFORMATION(); var strObjectName = ""; var nLength = 0; IntPtr ipTemp, ipHandle; if (!Win32API.Duplicate
Grasshopper.iics at 23-Sep-12 5:00am View
You would fail to get solution. You will try. You will not get there. You keep on trying. So you are glued to your system till you get the solution. Once you get there, you will be more confident and will try to see the end of any programming problem the same way. Keep working is the motto! 18 hours is a phrase. Dont we all intrinsically agree to it?
Grasshopper.iics at 18-Jan-12 0:08am View
This is already suggested in Alternative 1.
Grasshopper.iics at 18-Jan-12 0:07am View
Hi! Thanks for this. This is really something I missed out. :)
Grasshopper.iics at 14-Jan-12 0:32am View
I have accepted your alternative. But the essence of the topic is "Simple Conversion". Using pointers with unsafe is more efficient than color matrix. But the mentioned code here ( in main tip) is much simpler and the same loop can be used to produce binary image, edge detection, any other transform. :) Also the gray scale value can be obtained just by taking the average of R,G,B and replace it in all three channels.
Grasshopper.iics at 9-Jan-12 12:51pm View
Reason for my vote of 5 Great Work!

Advertise | Privacy | Mobile
Web01 | 2.8.140415.2 | Last Updated 1 Jan 1900
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid