|
Luc Pattyn wrote: 3. throw an exception and catch it where you need to.
Exceptions to control program flow? Isn't that a crime?
Regards,
Rob Philpott.
|
|
|
|
|
Hi,
Rob Philpott wrote: Exceptions to control program flow? Isn't that a crime?
Not always. The OP didn't mention why nor how often he would break out of all loops.
Exceptions always operate on program flow, they exist to make life easier and code more reliable. Not making good use of available means would be a crime. Depending on circumstances, one has to make a good choice, that is why I gave three possibilities.
|
|
|
|
|
Rob Philpott wrote: Exceptions to control program flow? Isn't that a crime?
Nope, if the condition that breaks the loops is exceptional.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Agreed. But use otherwise deserves a slap!
Regards,
Rob Philpott.
|
|
|
|
|
4.use goto .
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Absolutely. That is covered by "Not making good use of available means would be a crime".
|
|
|
|
|
Luc Pattyn wrote: Absolutely
I agree, in fact this is the perfect example of when a goto may be the most appropriate. It can be a useful statement - it's only because it can be (and has been) wildly misused that it's frowned upon.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
I love the goto statement, so I will use it.
It let's me think of the good times programming microcontrollers in assembly!!!
|
|
|
|
|
You can use break for the second loop and a boolean variable to be used inside the condition for loop 1 and set this to true from loop 2.
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
If you were using Java, I'd say "break OuterLoop;" (by adding the label "OuterLoop:" before the outer loop). But since you're in C#, you need to do this:
for ( ; ; )
{
for ( ; ; )
{
goto EndOfLoop;
}
}
EndOfLoop:
(You may also check the second example in this[^] MSDN reference page, although I wouldn't like to see it in actual code!)
|
|
|
|
|
I have been strugling with some issues regarding .NET Remoting mechanism.
Lets look at the 3 following simple lines -
httpChannel = new HttpChannel(props, null, new SoapServerFormatterSinkProvider());
ChannelServices.RegisterChannel(httpChannel);
RemotingConfiguration.RegisterWellKnownServiceType(typeof(Colors),"Colors", WellKnown.SingleCall)
OK.
I. what does RegisterChannel() actualy does?
or better yet, My client succeeds calling the server object even if I delete the RegisterChannel row.
So, why is it important?
II. Is there a way to progammaticly close a channel.
I mean if I unregister a channel - I can still call from client my remote object on the server
only if I close the server application the channel is closed . But I want to close him from within the server app.
10x a whole lot.
|
|
|
|
|
|
Don't bump your posts, it's very rude!
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
I'm not claiming any knowledge of this as I've never used it but I've just read the docs on the RegisterChannel and Unregister channel.
It appears that you may only need to use these methods to add/remove additional http or tcp channels to the registered channels list. By default, there are ones named "http" and "tcp" which is probably what's being used by your app. The registered channels list requires unique names which is why these methods are there in case you need to have more than one of either type.
I may be way off here - as i said I've never used it - but the docs seem to imply this.
Alt Register Channel Page[^]
RegisterChannel[^]
UnregisterChannel[^]
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
Yes, I read those docs, and maybe I missed something.
Channels require a number, Port number that is, and not a name.
The client connect through the port number .
And it can do that even if I dont register the channel at the server.
Why do I need to register the channel then?
And most important how do I release the channel?
10x.
|
|
|
|
|
I have a manager class which works as a proxy for connecting to mysql database. I have 2 methods in it, ConnectToDatabase and ExecuteQuery.
How should I write the class? Should I make it singleton?
Else, if I initiate the class each time, won't it take delay to connect to database??
Thanks in advance
Anvesh
|
|
|
|
|
anveshvm wrote: Else, if I initiate the class each time, won't it take delay to connect to database??
Initialization of your proxy class will not affect the delay to connect to database. And I don't think you need a singleton implementation here.
|
|
|
|
|
What about the connection object??
Should I keep the object static for the entire program execution scope.
Or should I connect to the database, each time, I have to execute a query?
|
|
|
|
|
anveshvm wrote: Or should I connect to the database, each time, I have to execute a query?
Yeah. That's the right approach.
anveshvm wrote: Should I keep the object static for the entire program execution scope.
You can keep it if the object is very expensive to build each time. But if it is a simple proxy class, keeping instance will not give performance difference.
|
|
|
|
|
|
Hi.
I am currently learning Linq and have some trouble with the Linq Contains function.
Here is what I first tried:
DataClasses1DataContext con = new DataClasses1DataContext(@"myconstring");
bool contains = con.Images.Contains(con.Images.First(n => n.imageID == 2));
I was pretty shure this would work but contains became false.
I then tried this:
Image myImg = con.Images.First(n => n.imageID == 2);
Image myImg3 = con.Images.First(n => n.imageID == 2);
if (myImg.Equals(myImg3))
Console.WriteLine("hurra");
But this did not work either. The two instances did not equal eachother.
I continued to try with this:
Image myImg2 = new Image
{
created = DateTime.Parse("23.05.2008 00:00:00"),
description = "Jalla",
imageID = 2,
name = "test",
searchWords = "halla",
systemID = 1
};
Image myImg4 = new Image
{
created = DateTime.Parse("23.05.2008 00:00:00"),
description = "Jalla",
imageID = 2,
name = "test",
searchWords = "halla",
systemID = 1
};
if (myImg2.Equals(myImg4))
Console.WriteLine("hurra");
But still they did not equal eachother. Only way I got this to work was by adding my img instances to a Array of Images[] and then do contains on this.
Image[] imgs = {myImg, myImg2, myImg3, myImg4};
bool contains = imgs.Contains(myImg2);
This gives contains a true value. So then I tought that this should work:
bool contains = con.Images.ToList().Contains(con.Images.First(n => n.imageID == 2));
But still contains is set to false.
So I am stumped. Anyone got anny sugestions or hints to why this does not work?
|
|
|
|
|
I found one workaround, but I still wonder if there is a bether way of doing this. Here is a solution that works:
bool contains = con.Images.ToList().Contains(con.Images.First(n => n.imageID == 2),new checker());
and the checker class:
public class checker : IEqualityComparer<image>
{
#region IEqualityComparer<image> Members
public bool Equals(Image x, Image y)
{
if (x.imageID == y.imageID)
return true;
else
{
return false;
}
}
public int GetHashCode(Image obj)
{
return obj.GetHashCode();
}
#endregion
}</image></image>
And I am still verry curious to why this dont work:
Image myImg2 = new Image
{
created = DateTime.Parse("23.05.2008 00:00:00"),
description = "Jalla",
imageID = 2,
name = "test",
searchWords = "halla",
systemID = 1
};
Image myImg4 = new Image
{
created = DateTime.Parse("23.05.2008 00:00:00"),
description = "Jalla",
imageID = 2,
name = "test",
searchWords = "halla",
systemID = 1
};
if (myImg2.Equals(myImg4))
Console.WriteLine("hurra");
I see no reason why these two instances should not equal eachother.
Here is the autogenerated Image class if anyone wants to know how that looks:
[Table(Name="dbo.Images")]
public partial class Image
{
private int _imageID;
private int _systemID;
private string _name;
private string _description;
private string _searchWords;
private System.DateTime _created;
private System.Nullable<system.datetime> _uppdated;
public Image()
{
}
[Column(Storage="_imageID", AutoSync=AutoSync.Always, DbType="Int NOT NULL IDENTITY", IsDbGenerated=true)]
public int imageID
{
get
{
return this._imageID;
}
set
{
if ((this._imageID != value))
{
this._imageID = value;
}
}
}
[Column(Storage="_systemID", DbType="Int NOT NULL")]
public int systemID
{
get
{
return this._systemID;
}
set
{
if ((this._systemID != value))
{
this._systemID = value;
}
}
}
[Column(Storage="_name", DbType="NVarChar(50) NOT NULL", CanBeNull=false)]
public string name
{
get
{
return this._name;
}
set
{
if ((this._name != value))
{
this._name = value;
}
}
}
[Column(Storage="_description", DbType="NVarChar(2000)")]
public string description
{
get
{
return this._description;
}
set
{
if ((this._description != value))
{
this._description = value;
}
}
}
[Column(Storage="_searchWords", DbType="NVarChar(2000)")]
public string searchWords
{
get
{
return this._searchWords;
}
set
{
if ((this._searchWords != value))
{
this._searchWords = value;
}
}
}
[Column(Storage="_created", DbType="DateTime NOT NULL")]
public System.DateTime created
{
get
{
return this._created;
}
set
{
if ((this._created != value))
{
this._created = value;
}
}
}
[Column(Storage="_uppdated", DbType="DateTime")]
public System.Nullable<system.datetime> uppdated
{
get
{
return this._uppdated;
}
set
{
if ((this._uppdated != value))
{
this._uppdated = value;
}
}
}
}</system.datetime></system.datetime>
|
|
|
|
|
Continued from "Another" one automation error...[^]
Ok, now, we going some steps forward...
System architecture is as follows: there are number of out-of-process COM servers. Each one uses an in-process server to access .NET interop. So:
[out-of-process COM server No.1] --\
[out-of-process COM server No.2] -- \
........................................................... --> [in-process COM component] --> [.NET interop component]
[out-of-process COM server No.n] ---/
This architecture required because it get possible to set each application with its own configuration provided to .NET component.
From previous attempts we know, that .NET component with satellite assemblies should be placed in working directory of COM application. In my case I need to duplicate them in each COM application. Or to install them to GAC.
So, I have placed all assemblies (including resources) to GAC and... right, I got automation error...
Fuslogvw does not point to some error. All assemblies were found and loaded from GAC successfully (except en-culture resource file that really does not present and embedded - it should not be a case, does not it?)
So the questions are:
- Is there some way to optimize present architecture scheme?
- Why GAC installation does not work?
- Does COM application need some additional permissions to access GAC?
Thanks to all.
modified on Wednesday, January 7, 2009 4:13 AM
|
|
|
|
|
Anyone having idea for pdf to word/doc conversion !!!!!
Don't walk as if u rule the world,walk as if u don't care who tha Hell rules the world ...
|
|
|
|
|
r u looking in c# or any language
|
|
|
|
|