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
SLOSifl
Aug 10, 2002


I have an issue with a .NET stored procedure hosted in SQL Server 2005.

Let's say I have a simple UDF that takes a float and returns whatever.ToString("c") to get a value formatted as currency. If I change my Windows regional settings to French, for example, I would expect to see the value 12345.67 displayed as "EUR 12 345,67". In US English I would see "$12,345.67".

However, it appears that the hosted instance of the .NET CLR doesn't use the Windows regional settings but rather the settings for SQL Server (understandably). What I can't figure out is how to control the language of the hosted .NET CLR.

I've spent a lot of time making sure my application is compatible with any locale. However, I've been assuming that SQL was going to stay in US English (which none of our clients seem to have a problem with). Now we need to control some formatting before things leave the database, and have to take a look at controlling that within SQL.

Any ideas?

Adbot
ADBOT LOVES YOU

pliable
Sep 26, 2003

this is what u get for "180 x 180 avatars"

this is what u fucking get u bithc
Fun Shoe
Hooray I've got a small question.

I'm watching a folder using the FileSystemWatcher class. I only need to watch for incoming .zip files. What is the easiest way to retreive the file name of a new .zip file?

I tried setting the NotifyFilter to NotifyFilter.FileName, thinking that would do it, but I guess not :confused:.

Thanks!

genki
Nov 12, 2003

SLOSifl posted:

Any ideas?
I think this deals with it:
http://blogs.msdn.com/sqlclr/archive/2005/06/15/429407.aspx
Basically, CurrentCulture is what you want to look into.

Sizzlechest
May 7, 2007
I've been told that you can compile Perl as a .NET program. If so, how do you handle graphics?

SLOSifl
Aug 10, 2002


genki posted:

I think this deals with it:
http://blogs.msdn.com/sqlclr/archive/2005/06/15/429407.aspx
Basically, CurrentCulture is what you want to look into.
Thanks for the quick response. This section describes what I was expecting the system to do by default:

quote:

The content of Thread.CurrentCulture is set for you to the default value specified in the control panel each time your code is invoked. The value is stable for the duration of your routine. Modifications you make to that property, or to any other static object, are not durable and will need to be redone each time your code runs.
However, after changing my entire system to French (or German, or whatever, I tried a few) and rebooting, the CurrentCulture was still English (United States). I am a bit confused, but I'm guessing there must be an additional configuration option I'm missing somewhere.

DLCinferno
Feb 22, 2003

Happy

pliable posted:

Hooray I've got a small question.

I'm watching a folder using the FileSystemWatcher class. I only need to watch for incoming .zip files. What is the easiest way to retreive the file name of a new .zip file?

I tried setting the NotifyFilter to NotifyFilter.FileName, thinking that would do it, but I guess not :confused:.

Thanks!
This crosspost might help you:

http://forums.somethingawful.com/showthread.php?action=showpost&postid=328456201

theHydralysk
Nov 21, 2003

CLOSE ENOUGH?

Sizzlechest posted:

I've been told that you can compile Perl as a .NET program. If so, how do you handle graphics?

You can use any of the .NET libraries with any .NET language, so you should be able to reference and use the same libraries as you would with C# or VB.Net. But if I remember from my short and unhappy time with perl, it's got a pretty funky object model so I couldn't speculate on syntax

DrOuD
Dec 25, 2003

theHydralysk posted:

You can use any of the .NET libraries with any .NET language, so you should be able to reference and use the same libraries as you would with C# or VB.Net. But if I remember from my short and unhappy time with perl, it's got a pretty funky object model so I couldn't speculate on syntax

PerlNET doesn't go both ways. You can reference perl from .NET because it has a custom interpreter, but the Perl code doesn't see the .NET libraries.

poopiehead
Oct 6, 2004

Fiend posted:

My apologies.

It sure would be useful to have Adobe Acrobat Document (.PDF) show up in the list of file types in the Save As dialog in word.

In case anyone has similar problems, I ended up using COM objects to open the file in Word and save it as a postscript file and then call up ghostscript to turn it into a pdf.

Magicmat
Aug 14, 2000

I've got the worst fucking attorneys

DLCinferno posted:

Excellent Win32 code

SLOSifl posted:

You can call SHGetFileInfo like this instead:
code:
public const uint SHGFI_ICON = 0x100;
public const uint SHGFI_LARGEICON = 0x0;
public const uint SHGFI_SMALLICON = 0x1; 
public const uint SHGFI_USEFILEATTRIBUTES = 0x10; 
public const uint FILE_ATTRIBUTE_NORMAL = 0x80;

SHGetFileInfo(file, FILE_ATTRIBUTE_NORMAL, ref shinfo, (uint)Marshal.SizeOf(shinfo), 
   SHGFI_ICON | SHGFI_SMALLICON | SHGFI_USEFILEATTRIBUTES)
With SHGFI_USEFILEATTRIBUTES, the filename doesn't have to be valid.
Excellent, those are both perfect for what I need! It turns out that ExtractImage() only gets the 32x32 icon of a file, even if there's a 16x16 icon in there, and there's no good way to override it. You can obviously resize the icon yourself, but that's a poor substitute for a native size. And it also can't do what SLOSifl showed how to do, which is get an icon for a "hypothetical" file. Thanks to you both, I would have never figured this out on my own!

Quick question: Do any other file types besides .exe and .ico have unique icons associated with them? SHGetFileInfo, unlike ExtractImage(), doesn't get thumbnails for images and the like, so I don't have to worry about them, only file with natively embedded icons. I'm trying to write a cacheing hash, so that I can only have one, say, .txt icon stored, instead of one for each txt file in the list.

Also, if I create an icon in a method call, as in
code:
imageList.Images.Add(Icon.FromHandle(shinfo.hIcon));
Is it bad that I don't dispose of it? Should I instead create a temporary Icon, pass it into the method call and then dispose of it?

Edit: Also, SHGetFileInfo doesn't seem to be able to get a folder's icon. What's the best way to do that?
Edit2: Nevermind, removing the SHGFI_USEFILEATTRIBUTES flag did it. I guess for "hypothetical" folder, I'll have to retrieve the folder icon of some presumed "normal" folder and use that as a generic folder icon.

Magicmat fucked around with this message at 03:42 on May 30, 2007

DLCinferno
Feb 22, 2003

Happy

Magicmat posted:

Edit2: Nevermind, removing the SHGFI_USEFILEATTRIBUTES flag did it. I guess for "hypothetical" folder, I'll have to retrieve the folder icon of some presumed "normal" folder and use that as a generic folder icon.
I suppose you could always use one of the SpecialFolders since you know most of them will always exist.

pliable
Sep 26, 2003

this is what u get for "180 x 180 avatars"

this is what u fucking get u bithc
Fun Shoe

Perfect. Thanks a ton!

IsaacNewton
Jun 18, 2005

Hey guys, I've been a lurker thus far but I have a little question..

I'm trying to get a list of networked computer names. I've found about Netapi32.NetServerEnum -- It work fine for finding the computer's workgroup computers but it completely ignore other workgroups.

Is there any way (managed or non) to get computers in other workgroups?

I don't think I can use System.DirectoryServices -- It requires an active domain server I believe?

Dromio
Oct 16, 2002
Sleeper
I'm having troubles with a session variable:

The user hits Default.aspx:
code:
protected void Page_Load(object sender, EventArgs e)
    {
    string CurrentSite = "Production";
    Session["CurrentSite"] = CurrentSite;
    Response.Redirect("TOC.aspx", false);
    }
But if I Trace.Write(CurrentSite) in TOC.aspx, it's always empty.
I thought adding "false" to the Redirect statement allowed it to set the session variables before moving on.

uXs
May 3, 2005

Mark it zero!

Dromio posted:

I'm having troubles with a session variable:

The user hits Default.aspx:
code:
protected void Page_Load(object sender, EventArgs e)
    {
    string CurrentSite = "Production";
    Session["CurrentSite"] = CurrentSite;
    Response.Redirect("TOC.aspx", false);
    }
But if I Trace.Write(CurrentSite) in TOC.aspx, it's always empty.
I thought adding "false" to the Redirect statement allowed it to set the session variables before moving on.

You are doing "string CurrentSite = (string) Session["CurrentSite"];" before you try to write it out, right ?

Magicmat
Aug 14, 2000

I've got the worst fucking attorneys
I'm having a little trouble figuring out the subtleties of .NET's garbage collection and manually disposing/finalizing an object and all that.

I'm using the previously posted method to get a file icon using the Win32 function SHGetFileInfo(), which returns a handle to an icon. I then using System.Drawing.Icon.FromHandle() to create an icon object out of that. Now, the MSDN page for FromHandle() states that "[w]hen using this method you must dispose of the resulting icon using the DestroyIcon method in the Win32 API to ensure the resources are released." Additionally, the Win32 documentation for SHGetFileInfo() states "[i]f SHGetFileInfo returns an icon handle [ . . . ], you are responsible for freeing it with DestroyIcon when you no longer need it." However, my .NET icon extraction code is encapsulated in a method which returns the Icon object and has no knowledge of the icon's lifetime.

I tried creating an Icon with FromHandle(), calling DestroyIcon() on the handle returned by SHGetFileInfo() and then returning the icon, but that just detroys the Icon's copy of the icon resource.

So, do I have to import and then call DestroyIcon() whenever the calling code finishes with an icon created via FromHandle(), or will Icon's own destructor take care of it? Or do I have to explicitly call the Icon object's Dispose() method when my calling code is done with the Icon?

And while we're here, do I ever need to manually call Dispose() on an object other than when I want to manually free the object's resources? That is, if I don't call Dispose() on some object, will the GC still clean it up, or will I get a leak? And what's the difference between Dispose() and Finalize()?

Magicmat fucked around with this message at 13:52 on Jun 4, 2007

jarito
Aug 26, 2003

Biscuit Hider
I'm trying to output a DateTime object in a specific format in an Xml file. The format of th XML can't be changed (even though it is wrong). The format I am looking for is:

code:
2007-06-03T20:36:32
When I output mine, I use this code:

code:
XmlConvert.ToString(party.ArrivalTime, XmlDateTimeSerializationMode.Unspecified);
Which gives me:

code:
2007-06-04T08:12:53.2318462
I have also tried XmlDateTimeSerializationMode.Local and just <DateTimeObject>.ToString(). Any ideas? It seems that Unspecified would be right if I could tell it not to show the ticks.

EDIT:
Figured it out myself:

code:
XmlConvert.ToString(party.ArrivalTime, "yyyy-MM-ddTHH:mm:ss" )
Should do the trick.

jarito fucked around with this message at 15:15 on Jun 4, 2007

Dromio
Oct 16, 2002
Sleeper

uXs posted:

You are doing "string CurrentSite = (string) Session["CurrentSite"];" before you try to write it out, right ?
I think that was the issue. I did several things at once and it started working.

Thank you!

Jethro
Jun 1, 2000

I was raised on the dairy, Bitch!

Magicmat posted:

And while we're here, do I ever need to manually call Dispose() on an object other than when I want to manually free the object's resources? That is, if I don't call Dispose() on some object, will the GC still clean it up, or will I get a leak? And what's the difference between Dispose() and Finalize()?
You should always call Dispose() manually on an object when you are done with it (except when you shouldn't).

And just for a little additional clarity, there are a few specific times when you should not Dispose() an IDisposable. The only time I can specifically think of when you shouldn't is when you get a sharepoint SPSite object through the SPControl.GetContextSite() method. These times when you shouldn't dispose of your object are usually made fairly clear, so if you're not sure you should probably do it.

Oh, and the difference between Dispose() and Finalize() is this: Dispose() is what you call when you're done with an object. Finalize() is what you never call ever because it's the garbage collector's job to call it. Finalize() will probably call Dispose(), so I guess it's not like the resources will be hanging around forever, but it's still bad practice to not Dispose() of your unmanaged resources, since you never know when the GC is going to get around to cleaning house.

Jethro fucked around with this message at 15:06 on Jun 4, 2007

poopiehead
Oct 6, 2004

I'm always a little foggy with Garbage collecting in .NET so take this with a grain of salt, but to add on to what Jethro was saying.

You need to call Dispose manually because the object holds some kind of resource that other objects can't get until you give it up. If you depend on the garbage collector to dispose, you have no control over when that happens. Depending on the program, the GC might only get called a few times a day or less. And all that time, you're holding the resource. There's a memory usage concern here too. When the gargage collector tries to reclaim an object that didn't have Dispose called, it will call dispose and then not reclaim the object until the next time it runs, so the object lives an extra garbage collection.

Horse Cock Johnson
Feb 11, 2005

Speed has everything to do with it. You see, the speed of the bottom informs the top how much pressure he's supposed to apply. Speed's the name of the game.
I figured this would be the best place to go for advice on this. Not really coding-related, but .NET-related.

I've been a .NET developer for the last 2 years in a small division of a much larger Fortune 500 company. I have a degree, I'm good at my job, my boss loves me and gives me glowing reviews, but with more and more of our development work being outsourced to either corporate IT or India I feel it's time for me to hit the job market.

I've had my resume out there for less than a week and I have two interviews on Wednesday for what sound like great opportunities. One problem - I've never ACTUALLY interviewed for a developer position before and am nervous as hell about it! I got my current job by being promoted from within because my (current) boss knew me and knew what I could do and knew he wanted me for the job, so he gave it to me.

I feel as though I'm a very competent .NET developer and the descriptions of these positions definitely don't sound like anything that I haven't done before, but can anybody tell me first hand what to expect during the interview process? I feel like if I have at least some idea of what to expect going in it'll really help with the anxiety. I really don't want to screw this up.

Any tips are greatly appreciated!

TheReverend
Jun 21, 2005

How do I set an ASP.NET page to not spazz out about SQL Timeouts? This one particualr page is going to display a fuckton of information and it takes the SQL server more than 30 seconds to do these calculations. Other than setting the connection string to timeoout at a greater number, is there any way of just setting this one particular page to be more patient?

KiwiDNA
Mar 6, 2003
I've got a really basic problem- I have an ASP.Net DropDownList that is supposed to call a function on change. I was handling this before with a button that called it and it was working fine, but I'd like to remove that step. I have:

<script runat="Server">
'Saves ResultsPerPage to Session
Sub SaveResultsCount(sender As Object, e As System.EventArgs)
...
End Sub
</script>

Followed by:

<asp:DropDownList id="selectResultsPerPage" onChange="SaveResultsCount" runat="Server" AutoPostBack="True">
...
</asp:DropDownList>

Unfortunately, when I change the value of the list, Firebug tells me that SaveResultsCount is not defined. The button, which works, also calls SaveResultsCount from its onServerClick method. Like I said, it's probably something simple but it's not coming to me.

SLOSifl
Aug 10, 2002


jarito posted:

I'm trying to output a DateTime object in a specific format in an Xml file. The format of th XML can't be changed (even though it is wrong). The format I am looking for is:

code:
2007-06-03T20:36:32
Use date.ToString ( "s" ). It produces "2007-06-04T11:23:37".

SLOSifl fucked around with this message at 19:27 on Jun 4, 2007

oberonix
Feb 21, 2007
that's doctor oberonix to you

KiwiDNA posted:

I've got a really basic problem- I have an ASP.Net DropDownList that is supposed to call a function on change. I was handling this before with a button that called it and it was working fine, but I'd like to remove that step. I have:

<script runat="Server">
'Saves ResultsPerPage to Session
Sub SaveResultsCount(sender As Object, e As System.EventArgs)
...
End Sub
</script>

Followed by:

<asp:DropDownList id="selectResultsPerPage" onChange="SaveResultsCount" runat="Server" AutoPostBack="True">
...
</asp:DropDownList>

Unfortunately, when I change the value of the list, Firebug tells me that SaveResultsCount is not defined. The button, which works, also calls SaveResultsCount from its onServerClick method. Like I said, it's probably something simple but it's not coming to me.

try using:

<asp:DropDownList id="selectResultsPerPage" OnSelectedIndexChanged="SaveResultsCount" runat="Server" AutoPostBack="True">

instead, the reason is probably that onchange is doing a client side javascript function call, which won't work and should give you that firebug error, versus the 'OnSelectedIndexChanged' which indicates which server side event handler function to call on postback. Hope that helps/makes sense.

oberonix fucked around with this message at 19:46 on Jun 4, 2007

MC Fruit Stripe
Nov 26, 2002

around and around we go
Shalinor recommended I ask you guys, so what book would you recommend for learning C# from scratch? I have the Microsoft Press step by step book but it seems a little basic, and I'd like to concentrate more on learning how to program and less on how to copy what's in the book.

Horse Cock Johnson
Feb 11, 2005

Speed has everything to do with it. You see, the speed of the bottom informs the top how much pressure he's supposed to apply. Speed's the name of the game.

MC Fruit Stripe posted:

Shalinor recommended I ask you guys, so what book would you recommend for learning C# from scratch? I have the Microsoft Press step by step book but it seems a little basic, and I'd like to concentrate more on learning how to program and less on how to copy what's in the book.

I liked Jesse Liberty's Programming C#. It's geared more toward someone who already has a good base of programming knowledge and covers some more advanced topics than would be in a book aimed at complete beginners. His writing style is also not too dry and easy to keep up with.

Factor Mystic
Mar 20, 2006

Baby's First Post-Apocalyptic Fiction
What's the best way to load text into a RichTextBox without having the application freeze? I've attempted various shenanigans involving background workers, threads, google, etc ad nausum (I'll spare you my actual code), and nothing I've tried avoids the 2-3 second lockup while loading large blocks. Help.

KiwiDNA
Mar 6, 2003

oberonix posted:

try using:

<asp:DropDownList id="selectResultsPerPage" OnSelectedIndexChanged="SaveResultsCount" runat="Server" AutoPostBack="True">

instead, the reason is probably that onchange is doing a client side javascript function call, which won't work and should give you that firebug error, versus the 'OnSelectedIndexChanged' which indicates which server side event handler function to call on postback. Hope that helps/makes sense.

That worked like a charm; thanks!

KiwiDNA
Mar 6, 2003
Unfortunately, one problem just led to another. I've got my DropDownList with three results per page options: 25, 50, and 100. When the page loads, it retrieves the current value of the ResultsPerPage variable from session and paginates properly. The drop down list also displays the proper option:

Select Case Session("ResultsPerPage").ToString()
Case "25"
selectResultsPerPage.SelectedIndex = 0
Case "50"
selectResultsPerPage.SelectedIndex = 1
Case "100"
selectResultsPerPage.SelectedIndex = 2
End Select
</HEAD>


I know I could have just set SelectedValue; I just wanted to see if this would work. The problem is that if the page loads initially with 50 or 100 results, it won't let me select 25. That is, I can select it and it appears to do the PostBack, but it does not fire the OnSelectedIndexChanged function and the List reverts back to 50 or 100. However, if I select 50 or 100 first, it works fine, and if I then select 25 after that, it will properly display 25 results.

This is perplexing as it is acting like 25 is selected initially (thus the OnSelectedIndexChanged function doesn't run), but the list does not display the 25 option and normally if you try to select the option that is already selected it does not PostBack. This poo poo is driving me batty.

MC Fruit Stripe
Nov 26, 2002

around and around we go

Mr. Herlihy posted:

I liked Jesse Liberty's Programming C#. It's geared more toward someone who already has a good base of programming knowledge and covers some more advanced topics than would be in a book aimed at complete beginners. His writing style is also not too dry and easy to keep up with.
Got lucky and found it at Borders on the way home. Shoot me your email address so I can request a refund if this book sucks! :)

biznatchio
Mar 31, 2001


Buglord

Magicmat posted:

I'm using the previously posted method to get a file icon using the Win32 function SHGetFileInfo(), which returns a handle to an icon. I then using System.Drawing.Icon.FromHandle() to create an icon object out of that. Now, the MSDN page for FromHandle() states that "[w]hen using this method you must dispose of the resulting icon using the DestroyIcon method in the Win32 API to ensure the resources are released." Additionally, the Win32 documentation for SHGetFileInfo() states "if SHGetFileInfo returns an icon handle [ . . . ], you are responsible for freeing it with DestroyIcon when you no longer need it." However, my .NET icon extraction code is encapsulated in a method which returns the Icon object and has no knowledge of the icon's lifetime.

I'm guessing here since I don't remember if this works the way I expect it to or not, but once you've created your Icon with FromHandle(), call Clone() on it to create another Icon object, Dispose of the first one, DestroyIcon your handle, and return the Icon created by the Clone.

There's a (reasonable) possibility the icon handle is shared between clones though. If that's the case you're gonna have to do a bit more heavy lifting.

Magicmat posted:

And while we're here, do I ever need to manually call Dispose() on an object other than when I want to manually free the object's resources? That is, if I don't call Dispose() on some object, will the GC still clean it up, or will I get a leak? And what's the difference between Dispose() and Finalize()?

You should strive to always, always call Dispose(). A couple reasons have already been mentioned in other responses (the most important being that you have direct control over when the unmanaged memory and things like network connections are actually closed), and a more important reason is that almost every object that implements IDisposable also includes a finalizer method that calls Dispose() when you forget to, and when a finalizer method exists, it has a substantial negative performance effect on the garbage collector (it makes your objects live a generation longer than necessary). Dispose() almost always calls GC.SupressFinalize(...), which unregisters the finalizer method from the object, and thereby avoids the inherent performance loss of a finalizer.

And a quick glossary:

Dispose() - You call this when you're done using an object. Comes from the IDisposable interface. There is absolutely nothing magic about this method (it doesn't do anything special that a normal method call doesn't do).
Finalize() - The runtime calls this when the object still needs to be cleaned up before the object can be truly collected. This method is intrinsic to the runtime, it doesn't come from an interface. It has magic attached to it in that if it exists on an object (and hasn't been manually supressed), the runtime ensures it will be called before the object's final collection.

Magicmat
Aug 14, 2000

I've got the worst fucking attorneys

biznatchio posted:

I'm guessing here since I don't remember if this works the way I expect it to or not, but once you've created your Icon with FromHandle(), call Clone() on it to create another Icon object, Dispose of the first one, DestroyIcon your handle, and return the Icon created by the Clone.

There's a (reasonable) possibility the icon handle is shared between clones though. If that's the case you're gonna have to do a bit more heavy lifting.
Your second statement is correct; calling DestroyIcon on the handle destroys the cloned Icon's icon resource. What's the best way to handle it in that case? Will the returned Icon's Dispose method destroy the icon resource for me?

Followup question: Is it bad form to instantiate an object which implements IDisposable as a temporary variable, for example as a parameter in a call to a method?

For example, here's my current code:
code:
Foo.Compare(
	new Bitmap(imageList.Images[imageList.Images.IndexOfKey(((FileInfo)i).Extension)]),
	IconExtractor.GetFileIcon(i.FullName, IconExtractor.IconSizes.Small).ToBitmap()))
I'm assuming that it's better form to declare those two parameters as local variables and then Dispose of them after the method call? Should I do the same on the ToBitmap method, declaring a third local variable to hold the bitmap form of the icon and then calling dispose on it instead of calling ToBitmap as part of the method parameters? e.g.,
code:
Bitmap myBitmap = new Bitmap(imageList.Images[imageList.Images.IndexOfKey(((FileInfo)i).Extension)]);
Icon existingIcon = IconExtractor.GetFileIcon(i.FullName, IconExtractor.IconSizes.Small);
Bitmap existingBitmap = existingIcon.ToBitmap();
try {
	Foo.Compare(myBitmap, existingBitmap);
}
finally
{
	myBitmap.Dispose();
	existingIcon.Dispose();
	existingBitmap.Dispose();
}

Magicmat fucked around with this message at 03:04 on Jun 5, 2007

Fastbreak
Jul 4, 2002
Don't worry, I had ten bucks.
Just have a quick question that I just noticed and is bugging me now. Whenever I am working in the designer for a typed Dataset, I noticed there is an int field and an integer field. I never noticed this because I would always tab over and just type 'int' and never look at the other options, but a coworker actually went to the drop down and selected 'integer'. What the hell is the difference?

Edit: And we are almost at 20 pages, should I start version 3 of this thread now?

FormerFatty
Jul 18, 2006
What's up .NET gurus? I'm a .NET newbie and am having a little trouble with trying to automate some web navigation with the WebBrowser control. I'm basically creating a UI that will log the user into a website and perform some tasks on the website but Im doing it through my app so that they have access to some helper functions and logging tools that I've developed as well.

My problem is that I'm having trouble with code executing before the webpage fully loads, thus screwing up the logic of my code. There is some code that checks the URL property of the WebBrowser control and performs tasks based on what that URL is. However the problem is that the URL is being checked before the webBrowser has a chance to fully load the page(and in turn have its URL property updated).

code:
  

//populate web fields with data entered into GUI textboxes
                webBrowser1.Document.GetElementById(@"Userid").SetAttribute("value", adminID.Text);
webBrowser1.Document.GetElementById(@"password").SetAttribute("value", adminPW.Text);

// simulate a click of the graphical button to submit data

webBrowser1.Document.GetElementById(@"gfxButton").InvokeMember("click");
              
                
//compare current URL to what the URL should be incase of incorrect login and handle improper userID and pw
//this is where the problem occurs... it checks the URL of webBrowser1 before it actually changes so that it will never process and incorrect login
                           if(webBrowser1.Url.ToString().Contains(@"incorrectlogin.jhtml"))
                {
                    
                    MessageBox.Show("Error Logging in -- Invalid userId/password.");
                 }
                else
                {

                //change the GUI of the form to show youre logged in
                
                username = adminID.Text;
                label14.Text = "Logged in as: " + username;
                label14.Visible = true;
                Logout.Visible = true;
                adminID.Visible = false;
                adminPW.Visible = false;
                adminLogin.Visible = false;
                label2.Visible = false;
                label3.Visible = false;
                
                 
                 
                }


I thought about using Thread.Sleep(5000) but I've found that the also halts the loading of a new page(and thus changing of the URL property) in the webBrowser control.

Should I somehow be using the navigated event? I'm stuck like a pig on a plate and could use some direction.

Thanks in advance,

Tim

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



Factor Mystic posted:

What's the best way to load text into a RichTextBox without having the application freeze? I've attempted various shenanigans involving background workers, threads, google, etc ad nausum (I'll spare you my actual code), and nothing I've tried avoids the 2-3 second lockup while loading large blocks. Help.

Put everything that's going to go into that box in a queue and listen for the AppIdle event (top of my head; not cut-and-pastable):

code:
Application.Idle += new EventHandler(AppIdle);
...
AppIdle(object, EventArgs)
{
   for(int i = 0; i < 100; i++)//100 should be OK but you may want to turn that down
      textBox.Add(queue.RemoveFront());
}
You could also be using it to release a semaphore that lets s thread run to populate the box or somthing like that, but the UI should remain fairly responsive this way.

poopiehead
Oct 6, 2004

Fastbreak posted:

Edit: And we are almost at 20 pages, should I start version 3 of this thread now?

I think we can have long threads now. Programming Questions thread is in the 50's and SALR thread is in the 60's

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



FormerFatty
code:
webBrowser1.DocumentComplete += new EventHandler(DocumentComplete_Handler);

DocumentComplete_Handler(object sender, DocumentCompleteEventArgs yarrgs)
{
      if(yarrgs.Url.ToString().Contains(@"incorrectlogin.jhtml"))
      {
        MessageBox.Show("Error Logging in -- Invalid userId/password.");
      }
      else
      {//change the GUI of the form to show youre logged in
         username = adminID.Text;
         label14.Text = "Logged in as: " + username;
         label14.Visible = true;
         Logout.Visible = true;
         adminID.Visible = false;
         adminPW.Visible = false;
         adminLogin.Visible = false;
         label2.Visible = false;
         label3.Visible = false;
     }
}
That will probably do what you want. Also, signing posts ouside the actual signature area is frowned upon here.

Senior Labor Eliminator, First-Against-The-Wall Division, Raiser of the Cost of Living, Defender of the Faith

Munkeymon fucked around with this message at 18:44 on Jun 5, 2007

FormerFatty
Jul 18, 2006

Munkeymon posted:

code:
webBrowser1.DocumentComplete += new EventHandler(DocumentComplete_Handler);

DocumentComplete_Handler(object sender, DocumentCompleteEventArgs yarrgs)
{
      if(yarrgs.Url.ToString().Contains(@"incorrectlogin.jhtml"))
      {
        MessageBox.Show("Error Logging in -- Invalid userId/password.");
      }
      else
      {//change the GUI of the form to show youre logged in
         username = adminID.Text;
         label14.Text = "Logged in as: " + username;
         label14.Visible = true;
         Logout.Visible = true;
         adminID.Visible = false;
         adminPW.Visible = false;
         adminLogin.Visible = false;
         label2.Visible = false;
         label3.Visible = false;
     }
}
That will probably do what you want. Also, signing posts ouside the actual signature area is frowned upon here.


Thanks... that event will trigger everytime the webBrowser finishes loading a page correct? I suppose I'd have to setup a large if statement to determine which page has finished loading(assuming Im going to be navigating between more than 2 pages).

Adbot
ADBOT LOVES YOU

oberonix
Feb 21, 2007
that's doctor oberonix to you

KiwiDNA posted:

Unfortunately, one problem just led to another. I've got my DropDownList with three results per page options: 25, 50, and 100. When the page loads, it retrieves the current value of the ResultsPerPage variable from session and paginates properly. The drop down list also displays the proper option:

Select Case Session("ResultsPerPage").ToString()
Case "25"
selectResultsPerPage.SelectedIndex = 0
Case "50"
selectResultsPerPage.SelectedIndex = 1
Case "100"
selectResultsPerPage.SelectedIndex = 2
End Select
</HEAD>


I know I could have just set SelectedValue; I just wanted to see if this would work. The problem is that if the page loads initially with 50 or 100 results, it won't let me select 25. That is, I can select it and it appears to do the PostBack, but it does not fire the OnSelectedIndexChanged function and the List reverts back to 50 or 100. However, if I select 50 or 100 first, it works fine, and if I then select 25 after that, it will properly display 25 results.

This is perplexing as it is acting like 25 is selected initially (thus the OnSelectedIndexChanged function doesn't run), but the list does not display the 25 option and normally if you try to select the option that is already selected it does not PostBack. This poo poo is driving me batty.

I would probably not set the selected index each time unless it is the first loading of the page, which is when that is really needed. The viewstate/browser should be able to hold the selection on subsequent visits just fine, so what you might consider is using the Page.IsPostBack value to see if it is not a postback, and then load the index from the session, otherwise just store to the session after each postback and let the dropdown selection manage itself.

I'm a little too confused with just what you've posted to say anything else meaningful, but if you want/need more help feel free to post some more code or pm me about it if you want.

  • Locked thread