|
Eagle32 wrote: //get the filePath String currentPath = picturesDataGridView.Rows[i].Cells[4].Value.ToString();
Yep that is it. The cell has no value => exception.
I wolud force something like "Invalid Bitmap" in the DB. So if there is no
file specified it(the program) will automatically put "Invalid Bitmap" and load/show a
red X or something kind of image. To check for null is expensive if you have many rows.
|
|
|
|
|
Hi,
I have already enabled the feature to show an invalid bitmap. The last row in the gridview does show an invalid bitmap.
I am just checking if i can have access to the the actual filepath of the animal image.
Any advice?
Thanks,
|
|
|
|
|
well use a try ... cath.
Even the File.Exists(...) will throw an exception if the current user
doesn't have enough privileges.
[Added]
but in your initial post you said:
The error occurs on the the following line:
if (File.Exists(AnimalsDataGridView.Rows[i].Cells[4].Value.ToString()))
This is the error:
"NullReference Exception was unhandled.
Object reference not set to an instance of an object."
This has nothing to do with the access to the file.
The null exception/stuff comes from your
AnimalsDataGridView.Rows[i].Cells[4].Value.ToString()
[/Added]
|
|
|
|
|
I discovered its because of the Blank row in the database.
I did the following but its not actually updating any of the rows. By the way no exceptions are being thrown if i do this:
foreach (DataGridViewRow row in AnimalDataGridView.Rows)
{
if (!row.IsNewRow)
{
{
}
}
}
}
Can you advise?
|
|
|
|
|
Don't allow null rows/fields.
First Open Up Access and fill in with a default Empty or Default text the fields that are null.
Now, lets say you have a table with 3 columns ID and AnimalName and AnimalPicture.
When you/the user introduce some data if the AnimalPicture textbox is empty than put in something like
Empty or Default.
I really don't know how you introduce/get the datas so without much detail that is the best I could
come up with.
|
|
|
|
|
Hi,
I have two methods, which are esentially doing similar jobs but have drastic speed differences. I don't know what is causing this speed difference. Here are the methods. The first one is like 100 times faster.
private void SaveNativeBinary(string file, long origin, long length, string opt)
{
SetSSVisible(StatusStrip, pbSmallPerc, true);
FileStream fs = null;
FileStream writer = null;
try { fs = new FileStream(file, FileMode.Open, FileAccess.Read); }
catch { throw new Exception("ERR"); }
try { writer = new FileStream(opt, FileMode.Create, FileAccess.ReadWrite); }
catch { throw new Exception("ERR"); }
fs.Seek(origin, SeekOrigin.Begin);
for (long pos = 0; pos < length; pos++)
{
if (pos % 204800 == 0)
{
SetSSValue(StatusStrip, pbSmallPerc, Convert.ToInt32(PercentageCalc(pos, length)) );
SetSSText(StatusStrip, lblStatus, "Aktarılıyor: " + BtoKB(pos).ToString() + " / " + BtoKB(length).ToString() + " KB (%" + PercentageCalc(pos, length) + ")");
}
writer.WriteByte((byte)fs.ReadByte());
}
fs.Close(); fs.Dispose(); writer.Close(); writer.Dispose();
SetSSVisible(StatusStrip, pbSmallPerc, false);
}
private void AppendBinToBin(string Container, string toAppend)
{
SetSSVisible(StatusStrip, pbSmallPerc, true);
FileStream fsA, fsB = null;
long tempLength = GetFileLength(toAppend);
try { fsA = new FileStream(Container, FileMode.Open, FileAccess.ReadWrite); }
catch { throw new Exception("ERR"); }
try { fsB = new FileStream(toAppend, FileMode.Open, FileAccess.Read); }
catch { throw new Exception("RRR"); }
try
{
fsA.Seek(0, SeekOrigin.End);
for (long pos = 0; pos < fsB.Length; pos++)
{
if (pos % 204800 == 0)
{
SetSSValue( StatusStrip, pbSmallPerc, Convert.ToInt32(PercentageCalc(pos, tempLength)) );
SetSSText( StatusStrip, lblStatus, "Aktarılıyor: " + BtoKB(pos).ToString() + " / " + BtoKB(tempLength).ToString() + " KB (%" + PercentageCalc(pos, tempLength) + ")" );
}
fsA.WriteByte( (byte)fsB.ReadByte() );
}
fsB.Close(); fsB.Dispose(); fsA.Close(); fsA.Dispose();
}
catch { throw new Exception("ERR."); }
SetSSVisible(StatusStrip, pbSmallPerc, false);
}
I am aware of the useless try-catch blocks, don't worry about them. They are not the cause of this speed difference.
Any help is appriciated.
Thanks.
|
|
|
|
|
Message Closed
modified 23-Nov-14 6:33am.
|
|
|
|
|
I am using the Process Explorer from SysInternals and the first method creates an IO traffic with the magnitude of approx. 32MB, but the second one can't even exceed 1MB.
|
|
|
|
|
Hi,
IMO the major suspect is the test in for (long pos = 0; pos < fsB.Length; pos++) which goes out and reads a property for each byte available. It may, or may not, be much better when running a release build; anyhow, I always make sure loop termination tests are as simple as possible, a local variable often does wonders.
|
|
|
|
|
Hi,
I am not sure I understood your point exactly. if(pos % 204800 == 0) block is used in both cases but they still have speed differences.
|
|
|
|
|
The point, as I understand it, was that calling fsB.get_Length (which is what you're doing when you ask the value of fsB.Length ) may secretly be doing something that takes more than a reasonable amount of time, which is true.
As proof, here is the code for FileStream.Length
public override long get_Length()
{
if (this._handle.IsClosed)
{
__Error.FileNotOpen();
}
if (!this.CanSeek)
{
__Error.SeekNotSupported();
}
int highSize = 0;
int fileSize = 0;
fileSize = Win32Native.GetFileSize(this._handle, out highSize);
if (fileSize == -1)
{
int errorCode = Marshal.GetLastWin32Error();
if (errorCode != 0)
{
__Error.WinIOError(errorCode, string.Empty);
}
}
long num4 = (highSize << 0x20) | ((long) ((ulong) fileSize));
if ((this._writePos > 0) && ((this._pos + this._writePos) > num4))
{
num4 = this._writePos + this._pos;
}
return num4;
}
Win32Native.GetFileSize uses P/Invoke to GetFileSize in kernel32.dll
Solution: store the length in a local variable (like Luc said)
|
|
|
|
|
Right.
I didn't know it was that bad. And why don't they use GetFileSizeEx, that one at least returns a long right away.
|
|
|
|
|
It is, I think, not even correct for sizes above 4GB.
I mean see this: (highSize << 0x20)
highSize is an int , and if you try to shift an int by 32, nothing happens, and it's only upcast after the shift.
There is just no way anyone they'd let something like this in after all the patches, so something else is going on. I went back to the reflector to check the MSIL:
L_004a: conv.i8 <--
L_004b: ldc.i4.s 0x20
L_004d: shl
edit: this must be the "offending" part of the code, it's the only place in the code where there is a shift by 0x20
So the actual code is right after all, that means it's a bug in Reflector, right? Or am I missing something?
|
|
|
|
|
1) Well spotted
2) I looked into it, and IL is OK, C# "disassembly" is wrong. Not the first bug in Reflector.
3) See, I would have used GetFileSizeEx and not have had the opportunity to make that mistake. But then it only exists since Windows Server 2000, so it would never have worked on Win98/Me .
|
|
|
|
|
Thank you all for your help. Now I got the idea and solved the problem. It would take me much longer to spot the cause by myself.
|
|
|
|
|
Now I got the idea. Thank you for your answers, this was a really hard thing to spot, for me.
|
|
|
|
|
Luc is talking about your use of fsB.Length , which is a property that you get every time. He's suggesting that you should store this and then work with that instead of fsB.Length in the loop."WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
I'm quite new to c# and dot.net. I've been scratching my head on this one for quite a while. I'm trying to build functionality similar to that shown here:
http://finviz.com/forex.ashx
I'm using the treemap code. I'm using the the text from the e.node.tooltip to disquish when the mouse hovers over a different node. I want to create a new child form that tracks the cursor like that shown in the above example. When the cursor passes over a new nodes I want to close the currently displayed form and display a new form associated with the node the mouse cursor is now hovering over. Here is were I capture the mouseover event:
void tmcMap_NodeMouseHover(object sender, NodeEventArgs e)
{
Form2 frmForm2 = new Form2();
if (e.Node.ToolTip != lastValue && frmForm2.Created != true)
{
lastValue = e.Node.ToolTip;
frmForm2.Text = "Child " + e.Node.ToolTip;
frmForm2.SetDesktopLocation(Cursor.Position.X, Cursor.Position.Y);
frmForm2.Show();
}
)
My problem is how to close frmForm2 prior to creating a new frmForm2 when the cursor hovers over a different node?
Any help would be appreciated!
|
|
|
|
|
Message Closed
modified 23-Nov-14 6:34am.
|
|
|
|
|
Thank's for the suggestion. There are a few thousand nodes in the treemap. I don't if that changes things? Also, I'm still stuck with the problem of how to make one form invisable and the next form visable when moving between nodes?modified on Friday, March 12, 2010 4:46 PM
|
|
|
|
|
Really bad idea. Creating a few thousand forms?? Seems a bit overkill.
|
|
|
|
|
Can't you do that with just the one form; hide it when not needed, make it show the data of the object of interest when hovering something. So have it invalidate when moving over another object, rather than closing one and opening another one. If doable, should be much cheaper and snappier.
|
|
|
|
|
Thank you that's a very good idea.
|
|
|
|
|
i made a remote desktop, when the client remote the server, server will be send update every time.
how to make it update every time(source code)?
thankQ..
|
|
|
|
|
I am having some problem with my c# program. The program was meant to ask a user for their age and a pin code, if the user is over 18, it ask them for their pin code and how many times they want their name displayed btw 5 and 20 but if they are not, a particular message comes up.
I am having problem setting up the variables. Do I have to store the age, pincode and numbers in int ?
This is what I have done so far and i have tried entering a wrong pin code but it didn;'t give me the messages i wanted.
class Program
{
static void Main(string[] args)
{
int age;
long pinCode;
int number;
age = 18;
pinCode = 1965;
number = 5;
What am I doing wrong?
|
|
|
|