|
Great.
Thank you.
Im @ work, so i have to wait till i get home. Ill let you know what happens.
|
|
|
|
|
I was at work too, but I was eerrrmm "compiling"
-Spacix
All your skynet questions[ ^] belong to solved
I dislike the black-and-white voting system on questions/answers.
|
|
|
|
|
I have loaded an image to a custom control when the user click on custom control to delete, i am dispoing the control plus deleting that pic.jpg where it resides but Windows is throwing an error saying it is begin used by other process.
This is how i am deleting but crashing
FileInfo f = new (imagefilepath)
f.Delete()<-----Crashing on this line
Thanks for your help
|
|
|
|
|
What Exception are you getting?
Either f might be null , otherwise you may get any of the exceptions mentioned here[^]
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Thanks for answering but my f isnot null.
The image/jpg is already in the folder and i am loading within my Picturebox Control and upon clicking on a Delete button I want to remove the control as well as its image from the sourcepath but i am getting this exception
The process cannot access the file C:\Documents and Settings\user\My Documents\Visual Studio 2008\Projects\bin\Debug\myTempDire\mainFolder\sFderName\images\2.jpg' because it is being used by another process.
|
|
|
|
|
Post how you are loading the image into the image box, by guess is that you did it via a image from file call.
So you'd need to close the stream to the file before accessing it.
I'd change it to the following:
When you load the image into the image box instead of pointing the box at the image. Read the image file into memory and inject the contents into the image box. That way the image box doesn't have a file stream connected to the file.
-Spacix
All your skynet questions[ ^] belong to solved
I dislike the black-and-white voting system on questions/answers.
|
|
|
|
|
Thanks for replying, Could you please show me in your example. I would better understand it then.
I shall be thankful
|
|
|
|
|
string fileName = @"C:\myImage.jpg";
using (StreamReader fileReader = new StreamReader(fileName))
using (Stream Img = fileReader.BaseStream)
{
this.pictureBox1.Image = new System.Drawing.Bitmap(Img);
}
untested/use at own risk/not liable/blah blah...
-Spacix
All your skynet questions[ ^] belong to solved
I dislike the black-and-white voting system on questions/answers.
|
|
|
|
|
By any chance are you using Image.FromFile to load the image? If so, the file is locked until you dispose the image. You need to either, dispose of the image before you delete it or, use an alternative method for loading the image such as FromStream which does not lock the method.
|
|
|
|
|
hi guy, I am loading image in the picturebox control like this on form load event. but Still the file is gettting locked. I don't know where the problem is getting. Any help Thanks.
string sourceFile =imagefilepath;
using( Stream stream = File.Open( sourceFile, FileMode.Open,FileAccess.Read, FileShare.Read ) )
{
try
{
Image image = Image.FromStream( stream );
stream.Close();
stream.Dispose();
pictureBox1.Image = image;
}
catch( Exception ex )
{
MessageBox.Show("so ");
}
}
|
|
|
|
|
That code should not give you a sharing violation when trying to delete the file further on. If it does, first make sure nobody else is actually using the file or keeping it open (perhaps not your application at all - or another part of it). Try using filemon (google that) to see what happens.
Some thoughts, however:
1. Make sure the picture box isn't still holding a reference to your image when you dispose of it. Otherwise, you will crash (either with an exception or with strangeness - this will depend on the current mood of your GDI). Always set pictureBox1.Image to null before you call image.Dispose() .
2. You are calling stream.Dispose() even though you're in a using block for stream . Don't. The using block does that for you when you exit it - regardless of exceptions or whatever else may happen. That's the reason using blocks exist. Also note that stream will close itself when it gets disposed (unless you do it first), so the stream.Close() call can be dropped as well.
Later,
--
Peter
|
|
|
|
|
Hy there,my problem is this: I have an image in my project resources,and a control that has an Image property set to that image. At runtime,I want to know what image is in that property. So i say
if(image == Properties.Resources.img1)
do something
I know that that is the image in the property,so why isn't it working?
|
|
|
|
|
System.Drawing implements neither the == operator nor the Equals() Method. So therefore it inherits the Equals() implementation from Object which checks object references. And so it fails. Using the == operator on an image is rather absurd anyhow. If it's an issue, you'll have to implement your own Equals or == routines and check the pixels one at a time, or use the object references to your advantage.
Scott P
“It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration.”
-Edsger Dijkstra
|
|
|
|
|
Any idea how to convert strings like "Tuesday 1st April 2008" to a DateTime.
I have tried DateTime.TryParse with different CultureInfo, without result
Kjetil
|
|
|
|
|
|
Thanks
Useful tip, but I was not able parse the date
DateTime dt = DateTime.ParseExact("April 1st 2008", "MMMM dd yyyy", new CultureInfo("en-US"), DateTimeStyles.None); //Failed
DateTime dt = DateTime.ParseExact("April 1 2008", "MMMM dd yyyy", new CultureInfo("en-US"), DateTimeStyles.None); //Failed
DateTime dt = DateTime.ParseExact("April 01 2008", "MMMM dd yyyy", new CultureInfo("en-US"), DateTimeStyles.None); //Succeeded
Any idea what formatstring to use ?
I could manipulate the string before parsing, but I'm parsing 8 different languages with different date format :-/
Kjetil
|
|
|
|
|
I don't think it's possible to have one generic format for the above examples.
Either some manipulation and FormatException handling is going to be required, or you're going to have to force them in your UI to enter data in an acceptable format by either separating the day, month and year fields into separate controls or using a DateTimePicker or something similar.
The second two examples shouldn't be too hard, but the date suffix in the first does not appear to be included in any of the custom format mechanisms - unless it's possible to use a wild card for the two characters?
It may be easier to create your own control that can handle the 8 different language formats - that will give you more flexibility if more are required later.
Dave
|
|
|
|
|
Guess I have to do some string-manipulation.
My app reads the dates from different sources, like word, excel, text or xml files, so it's not possible to solve this by UI changes...
Thanks
Kjetil
|
|
|
|
|
Hi All,
i have to show the starttime and the endtime of a activity in a progressbar. the bar has to peform one step every minute.
Can someone explain to me how to that with some code?
Thanx.
|
|
|
|
|
|
I have a problem while trying to execute a delegate in a different thread.
I have my application and autocad that has loaded my .net-dll.
I created a named-pipe-server (in an own thread in the dll for autocad) and send messages to it from my application. The thread with the server watis for the messages and executes a delegate on receiption. The method in my class (in the dll) is called and I can show it with a messagebox.
Till here everything is fine.
But now I want to open a new file for autocad and I try to use the regarding method-call (AcadApp.Application.DocumentManager.Open(file)). But here is the problem. I get an exception about internal error or wrong context. I'm still in the thread-context of my listening server and I think that is the problem. But how can I execute a function in the autocad-thread? My initialization-function that creates the listening-thread is executed in the autocad-thread-context so I can get Thread-object or whatever is needed.
|
|
|
|
|
You can try using MethodInvoker inside your thread to invloke the function in another thread.
Thanks
Laddie
Kindly rate if the answer was helpful
|
|
|
|
|
How does it work? Can you give me a sample? As you see I tried something but it doesn't work.
my code:
class IPCMsgHandler
{
private Thread listenThread = new Thread(ListeningThreadFunc);
...
public void Start()
{
listenThread.Start(this);
}
private static void ListeningThreadFunc(object data)
{
IPCMsgHandler helper = data as IPCMsgHandler;
...
MethodInvoker mi = new MethodInvoker(helper.OnMessage);
mi.Invoke();
...
}
}
public class AutoCADApplication : IExtensionApplication
{
IPCMsgHandler helper = null;
public void Initialize()
{
this.helper = new IPCMsgHandler("AutoCAD-IPCServer", new IPCMsgHandler.MessageHandler(this.OnIPCMessage));
this.helper.Start();
}
private void OnIPCMessage()
{
return;
}
|
|
|
|
|
Hi,
You need a reference to a control that has a window handle associated with it (something that inherits from System.Windows.Forms.Control) and lives on the Autocad main thread. Possibly you can get that through the Autocad API (with which I'm not at all familiar).
If you have that reference in a variable called control you invoke your delegate with control.Invoke(mi) instead of mi.Invoke() .
This routes the invocation through the event queue on the UI thread, which should solve your problem. Assuming you can get your hands on a suitable Control object of course...
--
Peter
|
|
|
|
|
That would work for a windows forms based API, and although I don't know the Autocad API either I wouldn't expect it to be Forms based. A better bet might be to implement a producer/consumer type of architecture[^].
Standards are great! Everybody should have one!
|
|
|
|