|
Luc - making progress here, but I'm a bit baffled by what is wrong here in this code:
public static void CloseAllForms()
{
MessageBox.Show("Number of open forms: " + Application.OpenForms.Count);
string tag;
int i=0;
foreach (Form frm in Application.OpenForms)
{
// frm.Dispose();
i = i + 1;
tag = frm.Tag.ToString();
MessageBox.Show("in loop, i="+i+" tag = "+tag);
}
}
What I'm trying to do is go through all the open forms that have a tag value populated, as those would be forms that I opened (The intial count that I display here seems to show more forms than I have opened, but I'll get to the bottom of this once I can figure out the simple things). In this code above, I'd sure think I'd be able to set the tag value to a string, and then display that in this loop. This code compiles, but when I execute it, I only get the initial count displaying, and I get one blank dialog box displaying. If I remove the "tag = frm...." line, the loop displays 4 or 5 times). So there's something I don't yet understand about how to access form names, or forms themselves. I think there's some issues with trying to set the "tag" variable above if the .Tag property has not yet been set on a form, and maybe that's my problem. But if you were to replace my code above with trying to loop through and display the .Tag property of forms, how would you do this? (Keeping in mind that not all open forms may have a tag value set).
|
|
|
|
|
genisyssoftware wrote: Keeping in mind that not all open forms may have a tag value set
You really should take your own advice here. What is in a Tag that hasn't been set by you?
And what happens when you execute null.ToString() ?
Suggestions:
- tell your IDE to always show line numbers in editor windows (for Visual Studio see here[^])
- put one big try-catch around the thing you are experimenting with, and within the catch show the entire Excecption.ToString()
- use the error messages and their line numbers to your advantage to pinpoint to location and cause of the problems you have.
genisyssoftware wrote: // frm.Dispose();
you shouldn't dispose of objects that still are referenced by some collection, unless the very next thing you do is killing the collection too. And you can't kill Application.OpenForms, it isn't even your collection.
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
Local announcement (Antwerp region): Lange Wapper? 59.24% waren verstandig genoeg om NEEN te stemmen; bye bye viaduct.
|
|
|
|
|
I implemented your try/catch suggestion (had to investigate the syntax here, as I'm a newbie), and this yielded the problem I had: you cannot set the .Tag property to a string if it is null. So I check for a null first, and things seem to be ok now. I'm still living in the "null is the same as a blank" logic which holds true in everything BUT C# in my experience But there are form names "AutogenForm" and "FrmMain" that are showing up in my "for" loop that I didn't instantiate, so that's why I need to only dispose of the "tagged" forms. (This may be a result of that 'bridge' I use, where maybe embedded - and hidden to me - is the instantiation of these forms, for whatever purpose they are for.). Your other suggestions here are worth noting, so thanks again Luc.
|
|
|
|
|
in many languages obj.method() or obj->method() is the way to apply a method to an object using a reference, sometimes simply called a pointer. You can dereference (i.e. use) a valid pointer, you can't dereference a null-pointer. Not in C/C++/Java/C# anyway.
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
Local announcement (Antwerp region): Lange Wapper? 59.24% waren verstandig genoeg om NEEN te stemmen; bye bye viaduct.
|
|
|
|
|
hey guys
I have this code:
axMedia.URL = Application.StartupPath + "\\playlist.asx";
it loads a playlist file and runs it in Media Player Addon.
PlayList file has nodes(tags) of links of websites
<Entry>
<ref href="www.blah.com/well.mp3" />
</Entry>
Am asking how can i check if there is a connection at all or not.
because there is no taste to load a file and computer has no connection to the net.
so before using axMedia.URL="playlist.asx";
i need to ask if there is already connection or not.
thanks.
|
|
|
|
|
Hi,
you can use P/Invoke and some Win32 functions to get Internet connection info; this:
enum LP_InternetConnectionState : int {
Configured=0x40,
LAN=0x02,
Modem=0x01,
OffLine=0x20,
Proxy=0x04,
RAS_installed=0x10
}
public static bool Connected() {
LP_InternetConnectionState description=0;
return InternetGetConnectedState(ref description, 0);
}
public static string ConnectionName {
get {
LP_InternetConnectionState description=0;
StringBuilder sb=new StringBuilder(512);
InternetGetConnectedStateEx(ref description, sb, sb.Capacity, 0);
return sb.ToString()+" ("+description.ToString()+")";
}
}
[DllImport("wininet.dll")]
static extern bool InternetGetConnectedState(ref LP_InternetConnectionState lpdwFlags,
int dwReserved);
[DllImport("wininet.dll")]
static extern bool InternetGetConnectedStateEx(ref LP_InternetConnectionState lpdwFlags,
StringBuilder name, int nameLength, int dwReserved);
should get you started.
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
Hi All,
I need to be able to connect to a database on a remote server without using an ODBC connection or anything of that kind. Does anyone know the parameters I would need to include in the connection string to achieve this?
Any help would be really appreciated.
Thanks
|
|
|
|
|
It is very hard to give a definitive answer to this without more detail, such as what type of database and so on but you could take a look on connectionstrings.com[^], which has details for most scenarios.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Hi Henry,
Thanks for your feedback.
Sorry about the lack of information. It's a SQL Anywhere 10 database that I'm trying to connect to and I'm writing in C# within the .NET framework.
Please let me know if there is any other information I can give you that would be helpful.
Thanks again,
MWRivera
|
|
|
|
|
Did you try the connectionstrings.com link I gave?
I have found for version 11[^], don't know if it will help for V 10 though as I'm not familiar with SQL Anywhere.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Henry,
Thanks I was able to connect after visiting the site you referred.
I had to play around with a combination of connects but got there in the end
The connection string is:
ENG=serverName;DBN=databaseName;Uid=username;Pwd=password;Links=tcpip(Host=server);
Do you know if the connection is using anything in particular to connect ADO.net or anything like that? Or is this a straight connection to the server (if that's at all possible).
Thanks again
|
|
|
|
|
MWRivera wrote: Do you know if the connection is using anything in particular to connect ADO.net or anything like that? Or is this a straight connection to the server (if that's at all possible).
That depends as much on the code that you have that uses the connection string. However it looks very much like ADO.Net.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Hello i have to create an application that read an existing drawing file .DWG and then aorder a robot to cut the shape drawin in a tissue
any help , which tools i should use , i am thinking about microsoft robotics and c#?
|
|
|
|
|
That's an ambitious task - this is for school ? Have you worked with Autocad in C# before ?
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
Hi
I have a void method which has an interface passing parameters in and parameters going out. This method is in one Visual Studio Project. However, when I open up my other Visual Studio Project which has a service reference to the other Visual Studio Project, and call the method, I can only see my in parameters and not out parameters. If I change the method to a function I can see both, but I don't want a function!
Can someone please explain why this is the case? Am I missing something?
Please help!
|
|
|
|
|
Hi,
in C# all callable code units are called methods, whether they return something or not (as opposed to Fortran or Basic subroutines and functions). And the behavior of parameters is independent of the return type.
So I suggest to check your facts again; if need be, show us the one that works well and the one that fails.
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
Since you are speaking about a Service Reference, I assume you are using WCF.
Apparently, WCF supports out parameters in operations (I didn't think it did), but can have some tricky behaviors with them (look this discussion, for instance).
I strongly suggest you to refactor it by changing the out parameter to return value, since your method don't already has one. Really, that will be effectively the same.
|
|
|
|
|
Yes, I am using WCF on a pipe between two applications, and yes I did notice the change in position of the input and output parameters but this isn't the problem.
If a have a method public bool mymethod (string abc, out string def) and call this method on in my other project, I can see output parameter and when I run the project a is returned. So, no great issues there, but if I change the method to public void (string abc, out string def) and go back to my project I only ever see the input parameter.
Any ideas?
|
|
|
|
|
AndyASPVB wrote: Any ideas?
Yes, refactor your code to not use out parameters. It is not a recommended design for WCF implementation and if you use a code analyzer it will flag this as a design issue that should be reviewed.
only two letters away from being an asset
|
|
|
|
|
Edit: It seems i have missread your post, if this doesn't help i am sorry
You didn't explain properly. There can be either solution, depends on your need
you can use ref keyword
Int32 getDouble = 6;
DoubleIt(ref getDouble);
public void DoubleIt(ref Int32 nevVal)
{
nevVal = nevVal * 2;
}
You can use Property
public class A
{
public A(){}
private Int32 _subInt;
public Int32 unit
{
get
{
return _subInt * 2;
}
set
{
subInt = value;
}
}
}
A a = new A();
a.unit = 4;
MessageBox.Show(a.unit.ToString());
|
|
|
|
|
can anybody help
i do have both window and web application that have to work on the same database file. they work fine in design time together I mean before deploying. Now i have deployed them independently and work fine except they can't share the database file.
the main problem is the windows application is installed in C:\program files...
while the web application is installed in the file path C:\inetpub\wwwroot\..
|
|
|
|
|
Djtech01 wrote: the main problem is the windows application is installed in C:\program files...
while the web application is installed in the file path C:\inetpub\wwwroot\..
of course they are. Why is that a problem ? Is it an access file ? Did you write your windows app to require the DB to be in the same folder as the exe ? If they share the same DB, that must mean that the windows app is designed to run on the server ? You need to give more details if you want help.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
First of all, thank you
secondly, sorry for the reason that I became silent, It is because I wasn't connected to the internet for the last 20 hrs.
the database file is SQL
Christian Graus wrote: Did you write your windows app to require the DB to be in the same folder as the exe ?
yes that is the problem. the windows app will search the database in the same location as the exe.
Christian Graus wrote: If they share the same DB, that must mean that the windows app is designed to run on the server ?
yea the windows app is designed to run on the server
hope to hear from you soon
thank you
|
|
|
|
|
I guess you don't want help then ?
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
I have made server with this code and in new form. When I push button that loads this form it stops.
private void server_Load(object sender, EventArgs e)
{
Int32 port = 1111;
IPAddress localAddr = IPAddress.Parse("127.0.0.1");
TcpListener tcpListener = new TcpListener(localAddr, port);
tcpListener.Start();
Console.WriteLine("Strežnik pognan...");
try
{
Socket socketForClient = tcpListener.AcceptSocket();
while (true)
{
if (socketForClient.Connected)
{
MessageBox.Show("Odjemalec povezan " + socketForClient.RemoteEndPoint.ToString(), "Napaka", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
NetworkStream networkStream = new NetworkStream(socketForClient);
StreamWriter streamWriter = new StreamWriter(networkStream);
StreamReader streamReader = new StreamReader(networkStream);
string line = streamReader.ReadLine();
textBox1.Text = "Sprejeto: " + line;
line = line.ToUpper();
streamWriter.WriteLine(line);
Console.WriteLine("Poslano: " + line);
streamWriter.Flush();
Console.WriteLine();
}
socketForClient.Close();
}
}
catch (Exception x)
{
Console.WriteLine(x.ToString());
}
When i connect client(also new form) to it..client form opens(client connected) but server form still isn't responding. Now i would like to type something in client and this message would be also writen lets say in textbox in server. If i delete while(true) it works but only first time. What should i do that it would work multiple times.
Please help
|
|
|
|