|
As long as the iTunesApp object is instantiated and you don't create a new instance of it each time, the event handler will stay bound until you release it.
-----------------------------
In just two days, tomorrow will be yesterday.
|
|
|
|
|
do you mean the itcoStatus object? The event handlers (in this case) aren't bound to the iTunesApp object.
Which bring up my point: if I simply keep overwriting the itcoStatus object with a new instance (not explicitly releasing the old instance) are the handlers bound to the new instance? Or did they become defunct when the old instance was stomped?
I realize my terms aren't very technical here, which reveals my real lack of knowledge about "instances"...
|
|
|
|
|
JoeRip wrote: do you mean the itcoStatus object?
Yes, I did mean the itcoStatus object. I guess I wasn't paying close enough attention to your example code.
JoeRip wrote: if I simply keep overwriting the itcoStatus object with a new instance (not explicitly releasing the old instance) are the handlers bound to the new instance? Or did they become defunct when the old instance was stomped?
Yes, if you overwrite the existing instance of the object with a new instance (by repeatedly calling itcoStatus = new iTunesConvertOperationStatus() you will loose the event handlers. Each time you call new you are creating an entirely new instance of the object.
In your example code, the first line:
iTunesConvertOperationStatus itcoStatus = null;
defines a variable named itcoStatus whose data type is a itunesConvertOperationsStatus object. When you then run code like this:
itcoStatus = new iTunesConvertOperationStatus()
you create a specific instance of that object in memory. The itcoStatus variable holds a reference (essentially a pointer) to the memory used by that instance. Each time you call new you get a new instance, which means you potentially get a different portion of memory so the itcoStatus variable ends up with a different reference.
-----------------------------
In just two days, tomorrow will be yesterday.
|
|
|
|
|
Dear all ,
i am making web application using C#, asp.net2.0(visual studio 2005) and sql2000, i want to know how can i securly pass password value from
client to server. PLease guide me.
Thanks
regards
imran khan
|
|
|
|
|
There is no 100% secure way. You should never pass the password around anyway, compare its hash value. There are plenty of resources here and elsewhere that cover this.
only two letters away from being an asset
|
|
|
|
|
do a search for terms like "challenge response" "salted hash" the subject is very complex and you should read as much as you can before implementing a solution as very subtle changes in the way you implement things make massive differences to security.
HTH
Russ
|
|
|
|
|
I want to get the error number when a exception occurs and i catch using the try {.. } catch {..} method.
i hav given like
catch { Exception ex}
{
}
but i didnt find any property of ex that gives me error number
Please help
REgards
Hari
|
|
|
|
|
Exceptions are string messages. You need something like ex.Message which gives the text message of the exception. Hope this helps you
|
|
|
|
|
There is no error number. .NET uses exceptions instead of error codes, with good reason. The exception defines the error, why return a code which, you hope, the user can turn back into an Exception so that it contains meaningful error. No code can give a call stack - it's a step backwards.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Yes, but I think he means he wants to differentiate between specific exceptions, so he can decide how to handle them programatically. In other words, how do you compare exceptions?
I've wondered this myself.
For almost any method or property in .NET, you can look at the help files and see what possible Exceptions they can throw. So it stands to reason that you can somehow say "if myException is X, do this" somehow.
I suppose you could compare the message text, but I doubt this is canonical, guaranteed to be unique or not change...
|
|
|
|
|
I'm a newb, but it looks like you have to know what exceptions can be thrown, and handle it in one of two ways:
try
{
DoWork();
}
catch (System.File.FileNotExists e)
{
}
OR,
catch (Exception e)
{
if (e is StackOverflowException ||
e is OutOfMemoryException)
DoSomething();
}
of course, you don't want to eat all exceptions, as I am in the second example. That will screw you.
|
|
|
|
|
JoeRip wrote: how do you compare exceptions?
You don't really compare exceptions. If you need to take different action based on different exceptions, you would write multiple catch handlers.
try
{
}
catch (System.NullReferenceException)
{
}
catch (System.InvalidOperationException)
{
}
The only caution is that you need to pay attention to the ordering of the catch handlers. The runtime will go through the catch handlers until it finds the first one that can handle the exception and then stop. This means that if you catch a base exception before a derived one, you will never handle the derived exception. For example:
try
{
}
catch (System.ArgumentException)
{
}
catch (System.ArgumentNullException)
{
}
try
{
}
catch (System.ArgumentNullException)
{
}
catch (System.ArgumentException)
{
}
In general, you only want to catch exceptions that your code can actually do something about and perform some sort of cleanup. You don't want to use them to help control your program flow as actually catching the exception is expensive.
-----------------------------
In just two days, tomorrow will be yesterday.
|
|
|
|
|
JoeRip wrote: So it stands to reason that you can somehow say "if myException is X, do this" somehow.
You can catch Exception and use the 'is' keyword, ( and hopefully rethrow if it's unhandled ), or you can specify in your catch statemetns what you wan to catch ( better ) Some exceptions have base classes, which you can also catch.
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|
try
{
// throw specific exception here
}
catch ( KeyNotFoundException ex )
{
}
catch ( InvalidOperationException ex )
{
}
catch ( Exception ex )
{
// all unhandled exceptions go here
}
HTH,
Martin
|
|
|
|
|
Hello, I'm fairly new to the C# world. What am I saying? I'm pretty new to coding all around and I've ran into a problem I have had to luck figuring out. So...
Before you ask, yes I have looked threw articles on the site. But none of them really help me. It is very hard to understand uncommented code at my skill level so it really does no good to me.
My first C# application is a simple RSS reader. I have most of the stuff done for it besides the TreeView. I cannot seem to figure out how to get this TreeView to grab data from my database and then display it in a certain way.
The tree view in the end should look like this:
<br />
TreeView<br />
<br />
|Folder<br />
|-RSS Channel/Feed<br />
|--News Item<br />
Ok so I have three folders in my database: Folders, Feeds, and NewsItems. The folders in the tree view will call the database table Folders, the rss channels/feed will call data from the Feeds table and finally the news items will call data from the NewsItems table.
How would I go about doing this? I have predefined values in all tables in the database, I'm not worried about adding new stuff to it yet and have it update. I just need to get the view to work.
Thanks for any help you can give
|
|
|
|
|
You can read data from the database using the System.Data.SqlClient.DataReader class to read data from your database. Once you have that data, you can create tree nodes from that data, then add those nodes to the treeview. Here's some idea of what this would look like:
SqlConnection connection = new SqlConnection("your connection string goes here");
SqlCommand myCommand = new SqlCommand("Select * from MyTable");
myCommand.Connection = connection;
SqlDataReader reader = myCommand.ExecuteReader();
while(reader.Reader())
{
string nodeText = reader.GetString(0);
TreeNode node = new TreeNode(nodeText);
myTreeView.Nodes.Add(node);
}
connection.Dispose();
myCommand.Dispose();
reader.Dispose();
|
|
|
|
|
Thanks for the help. I've ran into another problem while editing somethings. In order to use this it said to open the database, so I used:
connection.Open();
But it spits out an exception:
System.Data.SqlClient.SqlException was unhandled<br />
Message="An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)"
I don't understand how it is a remote connection if the database is the SQLServer that comes with C# Express 2005. Any ideas?
Thanks again for the help.
|
|
|
|
|
Oh, yes, you'll need to open a connection to SQL. This error occurs when SQL either isn't configured to allow connections to it from remote machines, or your connection string is invalid. Are you sure that connection string works? Try connecting to the database from, say, Sql Management Studio, or some other tool with that connection string to verify your connection string works.
p.s. judging by the error, named pipes might not work in this scenario. Try TCP.
|
|
|
|
|
Yup, 100KB app, 25KB of pictures, no sounds.
When it loads it imediatly takes up 9MB, now i know thats not alot, but where is it going? When the app loads it displays an empty listbox with 4 colums, two combo boxes with 10 items in, 5 buttons, and a text box.
It also creates 2 bools and a ListViewItem array, all empty. (The array is not given a size, just defined)
It does no processing, doesn't load any files, doesn't connect to the internet, until the user does something.
So err, why is it using so much and how do i fix it?
|
|
|
|
|
Well, that's the way things are nowadays, your first line of code is very expensive
(whatever it contains).
The good news is you can add 100,000 lines of code and still may need no more than say 50 MB
of memory.
Luc Pattyn
|
|
|
|
|
Indeed, i just checked a test app i made, which has one button, a text box, with just 100 lines of code total. It also yoinks itself 9MB.
It just seems a bit of a waste really.
|
|
|
|
|
Sure it is, but then those tons of megabytes are sitting there anyway, so why not fill them ?
(Same holds true for disks).
Luc Pattyn
|
|
|
|
|
That's the way .NET works. It allocates that "much" memory without actualy needing it. Reason is performance. Allocating one big block is more efficient then allocate many little blocks of memory. When later you need memory, "allocating" is as fast as changing one pointer. IIRC .NET does release this extra memory when OS is getting low on memory. No big deal in 99% of cases.
"Throughout human history, we have been dependent on machines to survive. Fate, it seems, is not without a sense of irony. " - Morpheus
|
|
|
|
|
As has been said, nothing to fix. Your usage is not linear, adding anouther 25kb of pictures will probably have no effect on your program size at all.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Ah, you learn somehting new every day. Im just suprised i never noticed this before, i've been doing it long enough. And with 2GB of RAM, it really doesn't make any difference.
|
|
|
|