15,797,167 members
Sign in
Sign in
Email
Password
Forgot your password?
Sign in with
home
articles
Browse Topics
>
Latest Articles
Top Articles
Posting/Update Guidelines
Article Help Forum
Submit an article or tip
Import GitHub Project
Import your Blog
quick answers
Q&A
Ask a Question
View Unanswered Questions
View All Questions
View C# questions
View C++ questions
View Javascript questions
View Python questions
View PHP questions
discussions
forums
CodeProject.AI Server
All Message Boards...
Application Lifecycle
>
Running a Business
Sales / Marketing
Collaboration / Beta Testing
Work Issues
Design and Architecture
Artificial Intelligence
ASP.NET
JavaScript
Internet of Things
C / C++ / MFC
>
ATL / WTL / STL
Managed C++/CLI
C#
Free Tools
Objective-C and Swift
Database
Hardware & Devices
>
System Admin
Hosting and Servers
Java
Linux Programming
Python
.NET (Core and Framework)
Android
iOS
Mobile
WPF
Visual Basic
Web Development
Site Bugs / Suggestions
Spam and Abuse Watch
features
features
Competitions
News
The Insider Newsletter
The Daily Build Newsletter
Newsletter archive
Surveys
CodeProject Stuff
community
lounge
Who's Who
Most Valuable Professionals
The Lounge
The CodeProject Blog
Where I Am: Member Photos
The Insider News
The Weird & The Wonderful
help
?
What is 'CodeProject'?
General FAQ
Ask a Question
Bugs and Suggestions
Article Help Forum
About Us
Search within:
Articles
Quick Answers
Messages
Comments by Grasshopper.iics (Top 12 by date)
Grasshopper.iics
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
21-Jan-13 20:47pm
View
You have set SeriesChartType.Point, it should be SeriesChartType.Column
Grasshopper.iics
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
21-Jan-13 18:33pm
View
Put argument to rest, please check with the suggested changes first!
Grasshopper.iics
21-Jan-13 3:17am
View
Deleted
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
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
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 stackoverflow.com)
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<string> GetFilesLockedBy(Process process)
{
var outp = new List<string>();
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<string> UnsafeGetFilesLockedBy(Process process)
{
try
{
var handles = GetHandles(process);
var files = new List<string>();
foreach (var handle in handles)
{
var file = GetFilePath(handle, process);
if (file != null) files.Add(file);
}
return files;
}
catch
{
return new List<string>();
}
}
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
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
18-Jan-12 0:08am
View
Deleted
This is already suggested in Alternative 1.
Grasshopper.iics
18-Jan-12 0:07am
View
Deleted
Hi! Thanks for this. This is really something I missed out. :)
Grasshopper.iics
14-Jan-12 0:32am
View
Deleted
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
9-Jan-12 12:51pm
View
Deleted
Reason for my vote of 5
Great Work!
Show More