Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Locked thread
cowboy beepboop
Feb 24, 2001

Gary the Llama posted:

I'm currently creating a Windows Forms application and I keep running into pesky UI issues. I'm just not happy with the way the program looks and is used.

I like some of the early stuff I saw that WPF could do but I'm afraid that going that route may require too much of my user base. I don't want them to have to download the .NET 3.0 framework for this application since I'm trying to appeal to the lowest common denominator. (Unless something has changed and WPF doesn't require additional framework downloads to work. Are there any stats on how many users have 3.0 already on their machine?)

What OS are you targetting? Vista has 3.0 preinstalled so WPF applications require no extra downloads. If it's XP take a look at targeting the client framework which is much smaller, as mentioned. You might get lucky and 3.5 (which is the first release with a client framework) will be out of beta by the time you release.

Adbot
ADBOT LOVES YOU

Bugs with gas
Jun 19, 2008
Um... I feel dumb asking this but... how do I get the borders around the tabs from ajax toolkit encompass something that is wider then the page?


After years of writing c and python for research purposes I somehow find myself in a ASP.NET developer position. I haven't even owned a windows box in several years.

MORE CURLY FRIES
Apr 8, 2004

tsunami posted:

I've never actually done this on an ASP.NET page so I'm not sure if it's any different, but I have done it with sockets. Anyway, could you spawn three threads that do the DB work and as they return, asynchronously update the page? Something similar to this: http://msdn.microsoft.com/en-us/library/3dasc8as.aspx. Although in that example they wait for all the threads to finish before displaying the results, while, as you said, you'd want to update the page immediately one by one as they finish.

Yeah, getting the info out of the database isn't the issue, it's the live updating of the page as the slower responses come back to the user.

Fiend
Dec 2, 2001

MORE CURLY FRIES posted:

Yeah, getting the info out of the database isn't the issue, it's the live updating of the page as the slower responses come back to the user.


I think before AJAX if I wanted something AJAXy to tell the user to wait while we're retrieving data, I'd make use of the Response object.
code:
Response.Write("<blink>YOU'VE WON A HOG!</blink><br/>");
Response.Flush();
System.Threading.Thread.Sleep(5000);
Response.Clear();
Response.Write("Please visit out sponsor...<br/>");
Response.Flush();
System.Threading.Thread.Sleep(2000);
Response.Clear();
Response.Write("...for more important details");
Response.Flush();
Have you looked into using a web service to get the data and trying something like a DynamicPopulate extender object?

Fastbreak
Jul 4, 2002
Don't worry, I had ten bucks.

Fiend posted:

I think before AJAX if I wanted something AJAXy to tell the user to wait while we're retrieving data, I'd make use of the Response object.
code:
Response.Write("<blink>YOU'VE WON A HOG!</blink><br/>");
Response.Flush();
System.Threading.Thread.Sleep(5000);
Response.Clear();
Response.Write("Please visit out sponsor...<br/>");
Response.Flush();
System.Threading.Thread.Sleep(2000);
Response.Clear();
Response.Write("...for more important details");
Response.Flush();
Have you looked into using a web service to get the data and trying something like a DynamicPopulate extender object?
The extender might work, but I am not sure about the response object. My first thought would be to have the 3 threads going and raise events as each one ends, which would update your page that checks every second or so for the status of the search. Make sense?

dwazegek posted:

Linq-to-Sql question:

I have a database table that will generally contain a fairly large number of rows (anywhere between 300k and 5M is normal). The primary key consists of a Guid and a DateTime.

Periodically I'll get a list of identifier objects (again, a Guid and DateTime) which denote the items rows that have to be deleted from the database.

Is there a clean and fast way to do this with linq-to-sql?

My current solution is to enumerate through the objects and call a stored procedure for each item, which has proven to be much faster than any linq-to-sql method I've used so far, but I might be missing something.

Can you show us the two different ways you are doing this in code and maybe we can find a place to make it go a little faster for you.

MORE CURLY FRIES
Apr 8, 2004

Fastbreak posted:

The extender might work, but I am not sure about the response object. My first thought would be to have the 3 threads going and raise events as each one ends, which would update your page that checks every second or so for the status of the search. Make sense?

Yeah I think this is heading in the direction that I'm wanting to go, I'll look into it next time I get a minute. Cheers!

fankey
Aug 31, 2001

I need a factory to create a bunch of objects. The way I'd like to do this is to have a static interface that can be implemented, have my factory find all instances of this interface in the Assembly, iterate through them and call the one that can handle the creation. Something like
code:
static interface ICreator
{
  bool CanCreate(object o);
  object Create(object o);
}
....
class SomeObject : ICreator
{
  public static bool CanCreate(object o)...
  public static object Create(object o)... 

}
....
// Create my object
foreach( Type t in Assembly.GetExecutingAssembly())
{
  // figure out here if it implements ICreator and call it if so...
}
As far as I can tell C# doesn't support static interfaces although the CLR does - is this the case? Is there a better solution besides having a class that needs to be instantiated to create my objects? My hope was to implement the static interface in the class that will be created by it.

geetee
Feb 2, 2004

>;[

fankey posted:

I need a factory to create a bunch of objects. The way I'd like to do this is to have a static interface that can be implemented, have my factory find all instances of this interface in the Assembly, iterate through them and call the one that can handle the creation.

I'm pretty new to C#, so take this with a grain of salt.

I ran into a similar situation and ended up with code like this:
code:
Type objType = Type.GetType(className);
objType.GetMethod("MyStaticMethod").Invoke(null, new Object[] {param1, param2});
I'm very interested in hearing about a better/more correct/non-stupid way to do this.

csammis
Aug 26, 2003

Mental Institution
Can static methods be overriden? If so, the methods can go in an abstract base class, and your objects that would have implemented ICreator can extend BaseCreator instead.

edit: Instead of searching for all instances of an interface, you could also decorate the classes which have those methods with an attribute. You wouldn't have the compile time verification, but the iterating part would be the same.

Kekekela
Oct 28, 2004

csammis posted:

Can static methods be overriden?

Nope.

Walked
Apr 14, 2003

Two [likely stupid] questions.

1) Can someone point me in the right direction on having a WPF/C# application minimize to the task-tray? I cant seem to find it.

2) And what about having a C# function in an application run at a set time of day? I want to run scheduledTaskFunction() at 4pm every day, for example. Any tips or resources?

csammis
Aug 26, 2003

Mental Institution

Kekekela posted:

Nope.

Didn't think so :)

Walked posted:

Two [likely stupid] questions.

1) Can someone point me in the right direction on having a WPF/C# application minimize to the task-tray? I cant seem to find it.

There is no notification icon control for WPF. You'll have to use the Winforms class NotifyIcon to present a tray icon, and like any application you'll have to code the "hide on minimize / show on icon click" logic yourself.

quote:

2) And what about having a C# function in an application run at a set time of day? I want to run scheduledTaskFunction() at 4pm every day, for example. Any tips or resources?

Your best bet, honestly, is to use the Windows Task Scheduler to run your application when you want it. Otherwise you'll just have to have a thread wake up every few seconds, see if it's 4PM, if it is do something and otherwise go back to sleep.

Walked
Apr 14, 2003

csammis posted:

Didn't think so :)


There is no notification icon control for WPF. You'll have to use the Winforms class NotifyIcon to present a tray icon, and like any application you'll have to code the "hide on minimize / show on icon click" logic yourself.


Your best bet, honestly, is to use the Windows Task Scheduler to run your application when you want it. Otherwise you'll just have to have a thread wake up every few seconds, see if it's 4PM, if it is do something and otherwise go back to sleep.

Going to need to keep the application running rather than task scheduler (at least I'd HEAVILY prefer to do so. Sleep / wake / check is fine I suppose, I'll have to look into that.

Sucks about the Tray icon, fortunately it is not vital or really even that important :)

DLCinferno
Feb 22, 2003

Happy

csammis posted:

Otherwise you'll just have to have a thread wake up every few seconds, see if it's 4PM, if it is do something and otherwise go back to sleep.
Huh? That seems like a fairly obtuse way of doing it. If you did want to do it in your app, I'd suggest using a timer class (there's a couple - System.Threading.Timer, System.Timer, System.Windows.Forms.Timer). When your app opens, just calculate the length of time between the current system time and 4PM, then set the timer to fire in that amount of time.

edit: and then reset the timer at 4PM for the next day in case the user keeps the app open, obviously.

Walked
Apr 14, 2003

DLCinferno posted:

Huh? That seems like a fairly obtuse way of doing it. If you did want to do it in your app, I'd suggest using a timer class (there's a couple - System.Threading.Timer, System.Timer, System.Windows.Forms.Timer). When your app opens, just calculate the length of time between the current system time and 4PM, then set the timer to fire in that amount of time.

edit: and then reset the timer at 4PM for the next day in case the user keeps the app open, obviously.

Awesome! Even better and ought to be rather simple to do. :)

DLCinferno
Feb 22, 2003

Happy

Walked posted:

Sucks about the Tray icon, fortunately it is not vital or really even that important :)
It's really easy to implement:

1) Drag-and-drop the notifyIcon to your form.
2) Double-click on notifyIcon and in the method add:
code:
this.WindowState = FormWindowState.Normal;
this.ShowInTaskbar = true;
3) Subscribe to the event "this.Resize" in your Form.Designer.cs file and in the method add:
code:
if (this.WindowState == System.Windows.Forms.FormWindowState.Minimized)
{
    this.ShowInTaskbar = false;
}
Done!


edit: I just tried it and double-clicking on the notify icon actually adds a handler for a double-click in the app (unlike most forms controls which add a single-click handler. Regardless, just add subscribe to the MouseClick instead of MouseDoubleClick.

Didn't want to confuse you with poor instructions. :)

DLCinferno fucked around with this message at 22:44 on Jul 15, 2008

fankey
Aug 31, 2001

csammis posted:

edit: Instead of searching for all instances of an interface, you could also decorate the classes which have those methods with an attribute. You wouldn't have the compile time verification, but the iterating part would be the same.
Since I was hoping for compile time verification I need the interface. I'll probably go with a separate creator class although it's still not 100% foolproof. What I'd really like is to force the definition of the creator class each time a new class ( derived from a common base ) is defined but I can't think of a way to accomplish that.

csammis
Aug 26, 2003

Mental Institution

DLCinferno posted:

It's really easy to implement:

Yes, in Winforms, but he asked about WPF.

quote:

Huh? That seems like a fairly obtuse way of doing it.

I don't know what I was thinking with the polling idea, but timers are going to drift over timespans that long. It's not a great solution.

csammis fucked around with this message at 23:16 on Jul 15, 2008

genki
Nov 12, 2003

DLCinferno posted:

Huh? That seems like a fairly obtuse way of doing it. If you did want to do it in your app, I'd suggest using a timer class (there's a couple - System.Threading.Timer, System.Timer, System.Windows.Forms.Timer). When your app opens, just calculate the length of time between the current system time and 4PM, then set the timer to fire in that amount of time.

edit: and then reset the timer at 4PM for the next day in case the user keeps the app open, obviously.
As a note, if you actually want the timer to go off at exactly 4pm, you'll want to recalculate the exact interval every time, otherwise the timer will likely start drifting.

Nothing too significant, but over time it adds up.

Also, System.Threading is the best timer to use. If you do a search on the various timers, you should find comparisons that suggest the same.

Practically speaking, though, none of these timers is really designed to work over intervals that large. I've made timers work over that interval, but you have to put in some extra work to make sure things run smooth.

DLCinferno
Feb 22, 2003

Happy

csammis posted:

Yes, in Winforms, but he asked about WPF.
Ahh, I did miss that but you can just use the Winforms one. Add a reference to System.Windows.Forms and one to System.Drawing (for the icon). Works in my test WPF app...

csammis posted:

I don't know what I was thinking with the polling idea, but timers are going to drift over timespans that long. It's not a great solution.

genki posted:

Practically speaking, though, none of these timers is really designed to work over intervals that large. I've made timers work over that interval, but you have to put in some extra work to make sure things run smooth.
Hmm, I haven't really had problems when I've done it in the past. But if you do find it drifting or something, just set the timer for 1 hour or the time until 4pm, whichever is shorter. Then every time it fires, check if it's actually 4pm, otherwise reset the timer again. If it's still drifting, use 1min intervals or something.

I mean, how else do you guys recommend doing scheduling?

genki
Nov 12, 2003

DLCinferno posted:

Hmm, I haven't really had problems when I've done it in the past. But if you do find it drifting or something, just set the timer for 1 hour or the time until 4pm, whichever is shorter. Then every time it fires, check if it's actually 4pm, otherwise reset the timer again. If it's still drifting, use 1min intervals or something.

I mean, how else do you guys recommend doing scheduling?
You can set it for intervals that large, but rather than just saying "add 24 hours", you have to say "add 24 hours to this time then see how far off the target time it is then adjust the interval by that amount".

DLCinferno
Feb 22, 2003

Happy

genki posted:

You can set it for intervals that large, but rather than just saying "add 24 hours", you have to say "add 24 hours to this time then see how far off the target time it is then adjust the interval by that amount".
That's a pretty small method to do it, though.
code:
public TimeSpan GetTimeUntil4PM()
{
        DateTime target;
        if (DateTime.Now.Hour >= 16)
        {
            target = new DateTime(DateTime.Now.AddDays(1).Year, DateTime.Now.AddDays(1).Month, DateTime.Now.AddDays(1).Day, 16, 0, 0);
        }
        else
        {
            target = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 16, 0, 0);
        }
        return target.Subtract(DateTime.Now);
}

genki
Nov 12, 2003
sure it's small! As long as you're aware of the issue it isn't a huge deal to work around it. I'm not sure what your point is... when I said extra work, I didn't mean it was unnecessarily huge, I just meant you can't assume adding 1 day will correctly give you 4pm every day for a year. The timers aren't exact and will give you anomalous results if you assume they are.

DLCinferno
Feb 22, 2003

Happy

genki posted:

sure it's small! As long as you're aware of the issue it isn't a huge deal to work around it. I'm not sure what your point is... when I said extra work, I didn't mean it was unnecessarily huge, I just meant you can't assume adding 1 day will correctly give you 4pm every day for a year. The timers aren't exact and will give you anomalous results if you assume they are.
Gotcha. It seemed to me that you were indicating it wasn't the best way or there was some other totally different way to do it; that's what I was responding to (not that I'm convinced my way is necessarily the best anyway).

Green_Machine
Jun 28, 2008

fankey posted:

I need a factory to create a bunch of objects. The way I'd like to do this is to have a static interface that can be implemented, have my factory find all instances of this interface in the Assembly, iterate through them and call the one that can handle the creation.

It's possible to do this. I suggest you look at Windsor container (http://www.castleproject.org/container/index.html). You can use it for inversion of control:

code:
/// <summary>
    /// Inversion of control container
    /// </summary>
    public static class IoC
    {
        private static IWindsorContainer m_container;

        public static void Init()
        {
            m_container = new WindsorContainer();

            m_container.Register(
                Component.For<IStuffFactory>().ImplementedBy<ConcreteStuffFactory>()
            );

            foreach (var type in typeof(IStuffMessageHandler).Assembly.GetTypes())
            {
                if (type.IsInterface || type.IsAbstract)
                    continue;
                if (typeof(IStuffMessageHandler).IsAssignableFrom(type) == false)
                    continue;
                m_container.Register(
                    Component.For(type.BaseType).ImplementedBy(type)
                    );
            }
        }

        public static object Resolve(Type type)
        {
            return m_container.Resolve(type);
        }
    }
So in this little example you can ask the IoC static class for an instance of an object supporting the IStuffFactory interface, or for an object supporting any interface that extends IStuffMessageHandler.

To relate it more directly to what you are asking for, the Windor container can be configured to return a newly-created object each time Resolve is called, and you can configure the manor of the object creation. So the IoC can act as your factory. You simply pass the type of object you want created into Resolve.

HappyHippo
Nov 19, 2003
Do you have an Air Miles Card?
What is the most painless way to display 3d objects with C#? It doesn't have to do anything fancy like textures, fullscreen or even be hardware accelerated. All I need is the ability to enter 3d triangles with colors and project them into 3d with the least overhead possible.

I had Direct3d working with managed C++ once, but I can't seem to transfer it over to C#, and the documentation isn't helping. When I look online there seems to be a million engines, and they're all way more than I need.

Walked
Apr 14, 2003

DLCinferno posted:

Ahh, I did miss that but you can just use the Winforms one. Add a reference to System.Windows.Forms and one to System.Drawing (for the icon). Works in my test WPF app...


Hmm, I haven't really had problems when I've done it in the past. But if you do find it drifting or something, just set the timer for 1 hour or the time until 4pm, whichever is shorter. Then every time it fires, check if it's actually 4pm, otherwise reset the timer again. If it's still drifting, use 1min intervals or something.

I mean, how else do you guys recommend doing scheduling?

DLCinferno, can you send me the test wpf app source in a rar so I can take a quick peek at it? I'm trying to wrap my head around how to use both winforms (havent touched before) and WPF at the same time.

Setash@gmail.com

If not, no big deal - I am playing around with it and think I can get it together on my own with enough time :)

DLCinferno
Feb 22, 2003

Happy

Walked posted:

DLCinferno, can you send me the test wpf app source in a rar so I can take a quick peek at it? I'm trying to wrap my head around how to use both winforms (havent touched before) and WPF at the same time.

Setash@gmail.com

If not, no big deal - I am playing around with it and think I can get it together on my own with enough time :)
It would be no problem, but to be honest, I know jack-all about WPF, although I consider myself mildly experienced in Winforms. Anyway, here's how I did the NotifyIcon in the WPF test app...

(To add the reference, it's easy, just go to the Solution Explorer, right-click on References, and from the .NET tab add both System.Windows.Forms and System.Drawing)

I'd be happy to help/answer any other questions if I can.

Here's the rar (I deleted the actual icon because it was licensed).

code:
namespace Test_Wpf
{
    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>
    public partial class Window1 : Window
    {
        public Window1()
        {
            InitializeComponent();

            System.Windows.Forms.NotifyIcon ni = new System.Windows.Forms.NotifyIcon();
            ni.Icon = new System.Drawing.Icon(@"C:\Users\DLCinferno\Documents\Visual Studio 2008\Projects\Test_Wpf\Test_Wpf\testicon.ico");
            ni.Text = "Another Test Icon";
            ni.MouseClick += new System.Windows.Forms.MouseEventHandler(ni_MouseClick);

        }

        void ni_MouseClick(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            MessageBox.Show("Tray Icon Clicked!");
        }
    }
}

DLCinferno
Feb 22, 2003

Happy

HappyHippo posted:

What is the most painless way to display 3d objects with C#? It doesn't have to do anything fancy like textures, fullscreen or even be hardware accelerated. All I need is the ability to enter 3d triangles with colors and project them into 3d with the least overhead possible.

I had Direct3d working with managed C++ once, but I can't seem to transfer it over to C#, and the documentation isn't helping. When I look online there seems to be a million engines, and they're all way more than I need.
I found this demo amazingly simple, definitely sparked my interest in WPF, and it's probably worth a look for you.

http://www.codeproject.com/KB/WPF/Wpf3DPrimer.aspx

DLCinferno
Feb 22, 2003

Happy

"genki posted:

sure it's small! As long as you're aware of the issue it isn't a huge deal to work around it. I'm not sure what your point is... when I said extra work, I didn't mean it was unnecessarily huge, I just meant you can't assume adding 1 day will correctly give you 4pm every day for a year. The timers aren't exact and will give you anomalous results if you assume they are.
Yay, 3x reply spam. Anyway, I reread your post and I realized there was some miscommunication...I was already advocating "resetting" the timer at each fire event. It would be kinda stupid to just set the timer 24hrs ahead instead of simply calling the "GetTimeUntil4PM" method, or whatever you do. I suppose I should have explicitly said so though.

If anyone does have a better solution I would actually really like to know because I'm currently working on a project that requires an index rebuild once a night, currently kicked off by a timer.

uXs
May 3, 2005

Mark it zero!

MORE CURLY FRIES posted:

Yeah, getting the info out of the database isn't the issue, it's the live updating of the page as the slower responses come back to the user.

I'd try splitting this up: one page that is shown to the user, and three that are basically just XML with the data. Using Javascript and a HttpRequest thingie, you can do the requests for data, and attach a callback function to each request. When the data is ready, use Javascript to show it to the user.

This is basically Ajax, but done in a rather manual way.

Walked
Apr 14, 2003

DLCinferno posted:

It would be no problem, but to be honest, I know jack-all about WPF, although I consider myself mildly experienced in Winforms. Anyway, here's how I did the NotifyIcon in the WPF test app...

(To add the reference, it's easy, just go to the Solution Explorer, right-click on References, and from the .NET tab add both System.Windows.Forms and System.Drawing)

I'd be happy to help/answer any other questions if I can.

Here's the rar (I deleted the actual icon because it was licensed).

code:
namespace Test_Wpf
{
    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>
    public partial class Window1 : Window
    {
        public Window1()
        {
            InitializeComponent();

            System.Windows.Forms.NotifyIcon ni = new System.Windows.Forms.NotifyIcon();
            ni.Icon = new System.Drawing.Icon(@"C:\Users\DLCinferno\Documents\Visual Studio 2008\Projects\Test_Wpf\Test_Wpf\testicon.ico");
            ni.Text = "Another Test Icon";
            ni.MouseClick += new System.Windows.Forms.MouseEventHandler(ni_MouseClick);

        }

        void ni_MouseClick(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            MessageBox.Show("Tray Icon Clicked!");
        }
    }
}

Hey, thank you very much, this should get me going and do what I need :) I appreciate it.

Rottbott
Jul 27, 2006
DMC

HappyHippo posted:

What is the most painless way to display 3d objects with C#? It doesn't have to do anything fancy like textures, fullscreen or even be hardware accelerated. All I need is the ability to enter 3d triangles with colors and project them into 3d with the least overhead possible.

I had Direct3d working with managed C++ once, but I can't seem to transfer it over to C#, and the documentation isn't helping. When I look online there seems to be a million engines, and they're all way more than I need.
You might try SlimDX, it works very well. It's a bit like Managed DirectX only up to date and cleaner.

Smugdog Millionaire
Sep 14, 2002

8) Blame Icefrog
Has anyone used Ruby.NET and would like to share their experience?
EDIT: Or IronRuby.

Smugdog Millionaire fucked around with this message at 21:39 on Jul 16, 2008

Kekekela
Oct 28, 2004

Free Bees posted:

Has anyone used Ruby.NET and would like to share their experience?

I was under the impression it was being abandoned since IronRuby made more sense once the DLR gained traction.

Smugdog Millionaire
Sep 14, 2002

8) Blame Icefrog

Kekekela posted:

I was under the impression it was being abandoned since IronRuby made more sense once the DLR gained traction.
I've revised my question to include IronRuby.

HappyHippo
Nov 19, 2003
Do you have an Air Miles Card?

DLCinferno posted:

I found this demo amazingly simple, definitely sparked my interest in WPF, and it's probably worth a look for you.

http://www.codeproject.com/KB/WPF/Wpf3DPrimer.aspx

Exactly what I wanted, thank you.

Factor Mystic
Mar 20, 2006

Baby's First Post-Apocalyptic Fiction
Is there any way to see parameter values for methods from the call stack? The use would be in a ThreadException handler, where I can capture any unhandled exceptions in the application and build a custom error report. I can easily use StackTrace for method names, line numbers, etc, but it would really be ace if I could also include parameter values in the report. An initial google indicates that this isn't possible, but I'd love to hear ideas...I can't think of anything besides a logging function called at the beginning of every method that would manually log each parameter value. I really don't want to have to do this, though, if there's a simple solution with Reflection magic or something.

Walked
Apr 14, 2003

code:
Ping p = new Ping();
PingReply reply;
I proceed to perform the ping operation, and return reply.Address.ToString();

Which is great, I even caught the exception where if its not a valid hoestname, it says so.

HOWEVER, I still get an exception if the hostname is valid, it has a DNS record, but it times out on the ping - so in the event it can be queried in DNS (or host file), but doesnt reply to a ping, I'm screwed.


How can I get the IP address that it send the ping to, in the event it doesnt reply (so I can see where it is going)

Half the point of this app is to take note of the IP address a hostname resolves to but does not reply to from :(


edit:
full code - please, I know its bad, I've been playing with solutions to make it work, I'll clean it up when I get the right results:

code:
        {

            Ping p = new Ping();
            PingReply reply = null;
            IPAddress ipAdd;
            
            try
            {
                ipAdd = IPAddress.Parse(box.Text);
                reply = p.Send(ipAdd, 100);


                reply = p.Send(ipAdd);
                if (reply.Status == IPStatus.Success)
                {
                    //MessageBox.Show(reply.Address.ToString());}
                }
                else
                { MessageBox.Show("No response from\n" + box.Text); }
            }
            catch (Exception e)
            {
                String exception = e.ToString(); //Just catching something because :o
                try
                {
                    reply = p.Send(box.Text);
                    if (reply.Status == IPStatus.Success)
                    { 
                        //MessageBox.Show(reply.Address.ToString()); 
                    }
                    else
                    { MessageBox.Show("No response from\n" + box.Text); }
                }
                catch (Exception any)
                {
                    String anyString = any.ToString();
                    MessageBox.Show("Invalid Hostname");
                }
            }

            if (reply != null)
            {
                return reply.Address.ToString();
                
            }
            else
            {
                return ("Invalid Host Name" + box.Text);

Walked fucked around with this message at 02:14 on Jul 17, 2008

Adbot
ADBOT LOVES YOU

dwazegek
Feb 11, 2005

WE CAN USE THIS :byodood:

Walked posted:

How can I get the IP address that it send the ping to, in the event it doesnt reply (so I can see where it is going)

Can't you just call Dns.GetHostAddresses?

Fastbreak posted:

Can you show us the two different ways you are doing this in code and maybe we can find a place to make it go a little faster for you.

code:
public class SomeIdentifier
{
    public Guid ID { get; set; }

    public DateTime Timestamp { get; set; }
}

//The current, non-linq way:
public void DeleteItems(IEnumerable<SomeIdentifier> items)
{
    using (var con = new SqlConnection(ConnectionString))
    {
        con.Open();
        foreach (var item in items)
        {
            using (var cmd = con.CreateCommand())
            {
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.CommandText = "DeleteSomeItem";  
                cmd.Parameters.AddWithValue("ID", item.ID);
                cmd.Parameters.AddWithValue("Timestamp", item.Timestamp);

                cmd.ExecuteNonQuery();
            }
        }
    }
}

//linq stuff I've tried:
public void DeleteItems(IEnumerable<SomeIdentifier> items)
{
    using (var db = GetDataContext())
    {
        foreach (var item in items)
        {
            var result = (from si in db.SomeItems
                          where si.ID == item.ID && si.Timestamp == item.Timestamp
                          select si).First();

            db.SomeItems.DeleteOnSubmit(result);
        }

        db.SubmitChanges();
    }
}
The stored procedure is just a simple "DELETE FROM [Table] WHERE [ID] = @ID AND [Timestamp] = @Timestamp".

The linq solution I posted is much slower, probably because it first pulls an item from the database, then issues a seperate delete command for that item.
It doesn't really seem to matter if I change it to collect all the items first and then call DeleteAllOnSubmit.

Anyway, it's not really important, I just finished moving our entire database communication to linq-to-sql, and this is the last thing that didn't make the move, so it's more for completeness' sake.

  • Locked thread