|
I don't often get told I'm too subtle! Normally it's quite the reverse. It'll be a pipe and carpet slippers next, I'm afraid...
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
|
|
|
|
|
OriginalGriff wrote: It'll be a pipe and carpet slippers next
Now you've lost me, you really need to start formulating more clearly.
|
|
|
|
|
I have some callback method that set on my queue some bitmap.
This callback is called every 3 millisecond.
What i mean is that my queue will be fill up with a new bitmap every 60 Millisecond.
I trying to get the first picture ( this is queue ... ) and show it on pictureBox - but i get some "external error e0434352" and i don't understand why and what this exception error mean.
This external exception appear on the line that i update the image ( this.pictureBox1.Image = Image.FromHbitmap( img ) )
Please someone can help me ? - i really don't have any idea what the problem can be and how to solve it.
private void CallBack( object sender, IntPtr e )
{
lock( IncomingBmp )
{
IncomingBmp.Enqueue ( e );
if( IncomingBmp.Count > 10)
{
UpdateBitmap( IncomingBmp.Dequeue() );
}
}
}
private void UpdateBitmap( IntPtr img )
{
if( this.pictureBox1.InvokeRequired == true )
{
UpdateBitmapCallback p = new UpdateBitmapCallback( UpdateBitmap );
this.Invoke( p, img );
}
else
{
Image oldImage = this.pictureBox1.Image;
this.pictureBox1.Image = Image.FromHbitmap( img );
if( oldImage != null )
oldImage.Dispose();
}
}
|
|
|
|
|
So your callback is getting a pointer/handle to some data, and later on you try and transform that pointer/handle into a managed object. Who is to say the pointer/handle is still valid (pointing at valid data) at the moment you try and use it?
IMO what you should do is have the callback get the data and turn it into an image right away. Then you could queue the image itself for later use.
Furthermore the MSDN doc on FromHBitmap says:
"The FromHbitmap method makes a copy of the GDI bitmap; so you can release the incoming GDI bitmap using the GDI DeleteObject method immediately after creating the new Image."
Are you taking care of that?
|
|
|
|
|
hello,
i used to write c# programs but i didn't write for more than 2 years and you can say i forgot every thing about c#.
and now i am back to c# and programming in general so i am trying to write a simple c# program and i am stuck in the following:
-1- i have inserted a Button on the main form, this button is supposed to call another form when it is clicked:
private void Button1_Click(object sender, EventArgs e)
{
?????????
}
what i am suppose to do to call the other form.
-2- is there an example showing how to deal with office access database. how to insert new items and to call them from the database.
i am using Visual studio 2008 and office 2007.
thank you for your help.
|
|
|
|
|
Did you tried MSDN? I am 100% sure you will get examples for these things there.
|
|
|
|
|
thank you. i will start using it.
|
|
|
|
|
MyNewForm mnf = new MyNewForm();
mnf.ShowDialog();
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
|
|
|
|
|
thanks.
|
|
|
|
|
Hey friends,
I hav a small question. I'm starting to develop a C# Windows application from scratch. The application will need a datasource. Previously I've always developed using MS SQL Server but for this app I don't want to have 'having an sql server instance' as a requirement.
I want a single file database or something, and is possible with LINQ support. What kind of datasource are recommended?
|
|
|
|
|
How much data does your application uses? If it not much, you can use XML or Access. If it is large amount of data, use a real database.
|
|
|
|
|
It's hard t say what would work best for you since you gave no real requirements other than single file and not SQLServer.
Using an Access (Jet) database is one possibility. The problems with Access are its size limitation and that it's a pain-in-the-butt to create a new Access database programatically. If you don't have to worry about those things, then Access (Jet) might work just fine.
You might also consider using SQLite, although it also has limitations and I'm not sure if it supports Linq.
CQ de W5ALT
Walt Fair, Jr., P. E.
Comport Computing
Specializing in Technical Engineering Software
|
|
|
|
|
try db4o.
It's an object database, meaning you store the objects directly. It's fast to
develop and easy to use. But only for local stuff. I wouldn't use it as a DB server.
It's free under GPL. The learning curve it's a breeze.
The new version suports LINQ too.
Here is a direct link to their tutorial.
I bug
|
|
|
|
|
static string DecodeUnicode(string s)
{
StringBuilder sb=new StringBuilder();
while (s.Length!=0)
{
sb.Append((char)int.Parse(s.Substring(2, 4), NumberStyles.HexNumber));
s=s.Substring(6);
}
return sb.ToString();
}
string s="\\u092A\\u094B\\u0937\\u093E\\u0939\\u093E\\u0930";
s=DecodeUnicode(s);
I am using above code to remove "\\" into "\". But if we add some text in this string its gives error.
e.g.:string s="\\u092A\\u094B\\u0937\\u093E\\u0939\\u093E\\u0930 abc";
error msg shows: Input string doesn't match.
i think this issue occur due to, i divide substring(2,4)
please guide me.
thanx
|
|
|
|
|
if your input string does not consist only of \\uddd sequences (where each d is a digit), then you need to search for such substrings and replace them one by one by the character they represent.
|
|
|
|
|
Well, first... If you type this:
string s="\\u092A\\u094B\\u0937\\u093E\\u0939\\u093E\\u0930";
Then the compiler is already converting the double-backslashes to single-backslashes... But assuming you actually have the doubles in the string...
Try just using string.Replace() ...
s = s.Replace(@"\\",@"\")
The @ sign before the first quote tells C# to ignore the escape characters (Including things like newlines and tabs)... You could also write s.Replace("\\\\","\\");
|
|
|
|
|
Hi Ian,
this is yet another episode in a long story, I still don't know what his application is about, but I think of it as some sort of compiler, where the input actually does contain double slashed codes, and needs to treat the escapes. In the current post, the double backslashes are present inside some string which should not have been displayed as a string literal; proof of that is it all worked well until he appended "abc". I'm afraid he is still not really grasping what the escape mechanism does and doesn't do.
|
|
|
|
|
Well, Replace is still easier
|
|
|
|
|
I've been battling with this issue for a long time and have yet to find a solution that is reliable.
This is the basic flow.
UnmanagedResource.Open(delegate callback);
...
callback called with Opened message
...
... // app does interesting stuff
...
UnmanagedResource.Close(); // will return immediately
...
callback called with Closed message
The problem I have is this. If Close isn't called by the consumer before ending the app then nasty Earth ending stuff can happen. I can of course use the dispose pattern to call Close automatically and I have implemented just that.
This still leaves an issue with the callback though as there is no mechanism on the unmanaged side to unregister from this so the callback will happen but the managed delegate/class instance may no longer be valid when it does.
Is there a method of keeping a class/delegate instance alive inside a Dispose called from a finalizer until a specific callback has happened? Perhaps a blocking loop in Dispose that checks a value that is set in the callback. If this is viable, what is the best way to implement this as depending on the system, the callback may occur on the same or a different thread (I'm no threading expert!).
DaveIf this helped, please vote & accept answer!
Binging is like googling, it just feels dirtier.
Please take your VB.NET out of our nice case sensitive forum.(Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
|
|
|
|
|
|
Hi Luc,
We always seem to meet on unmanaged stuff
1 & 2 don't help as I need the finalizer to be called so I can call Dispose and in turn Close . I can't just allow it to 'disappear' as an Open resource may then be left behind. I can obviously blame any problems on the consumer for not specifically disposing/closing but I'd rather assume they are idots and have a failsafe in place.
3 will be of use if I can find a way to block until the callback triggered by close occurs.
4. This is a class library so no WinForms unfortunately (I'm back finishing off the MIDI thing and possibly adding audio as I mentioned the other day).
DaveIf this helped, please vote & accept answer!
Binging is like googling, it just feels dirtier.
Please take your VB.NET out of our nice case sensitive forum.(Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
|
|
|
|
|
You probably need to split each of those objects X into two managed objects:
- XFunctionality gets exposed to the user and takes care of real functionality;
- XUnmanagedResource, hidden from the user, deals with the management of the unmanaged resource only.
Obviously XFunctionality would create its XUnmanagedResource instance and keep a reference to it, probably when you call an Open(). The callback method however would be part of XFunctionality, so the XUnmanagedResource finalizer can cause it to be called even after XUnmanagedResource has died.
And XFunctionality would also contain a static List<XFunctionality> holding all live XFunctionality instances preventing any of them being collected without being closed first; the close-callback should then remove its XFunctionality object from that collection, making it collectible. And you could provide a static CloseAll() method enforcing all of the remaining ones to be closed.
|
|
|
|
|
Hmmm... I'm pretty sure I've already tried it like this. I'll do a quick mock up tonight and let you know.
DaveIf this helped, please vote & accept answer!
Binging is like googling, it just feels dirtier.
Please take your VB.NET out of our nice case sensitive forum.(Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
|
|
|
|
|
Hi Luc,
I've done alot of experimentation with this over the last 24 hours which has lead to trying SafeHandles and all kinds of stuff.
It seems the key to the solution is:
Luc Pattyn wrote: XFunctionality would also contain a static List<XFunctionality>
In the MidiDevice base class I have created two static List s which are filled in a static constructor.
protected static List<MidiInput> inputs;
protected static List<MidiOutput> outputs;
static MidiDevice()
{
uint inputCount = NativeMethods.midiInGetNumDevs();
inputs = new List<MidiInput>((int)inputCount);
if (inputCount > 0)
for (uint u = 0; u < inputCount; u++)
inputs.Add(new MidiInput(u));
uint outputCount = NativeMethods.midiOutGetNumDevs();
outputs = new List<MidiOutput>((int)outputCount);
if (outputCount > 0)
for (uint u = 0; u < outputCount; u++)
outputs.Add(new MidiOutput(u));
}
which are exposed as ReadOnlyCollection s in the derived classes.
public static ReadOnlyCollection<MidiOutput> Outputs
{
get { return outputs.AsReadOnly(); }
}
This seems to be enough to trigger the finalizer for each MidiDevice instance on application close where I can call Close (I'm using GC.KeepAlive(this) as an added safety net) and the callback also happens.
~MidiDevice()
{
Close();
GC.KeepAlive(this);
}
This is working perfectly with the hardware I'm using for testing at the moment!
Any further thoughts or comments?
DaveIf this helped, please vote & accept answer!
Binging is like googling, it just feels dirtier.
Please take your VB.NET out of our nice case sensitive forum.(Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
|
|
|
|
|
Hi Dave,
this sounds good
Only petty comments such as:
- no need to test inputCount, outputCount
- I don't like the method name midiInGetNumDevs (verb not first, casing wrong)
- you'd better use int everywhere, there's too many casts right now.
And then I'm completely lost at GC.KeepAlive(this);
1. what is "this"? isn't everything static there? how can that compile? I would never expect "this" in KeepAlive, as it is "this" that is running the code anyhow.
2. and do you really need it?
|
|
|
|