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
gibbed
Apr 10, 2006

csammis posted:

Which is why I qualified my example by saying it was the Community edition :confused:
I guess I worded that badly, I was only clarifying what the non-community editions do.

Adbot
ADBOT LOVES YOU

Factor Mystic
Mar 20, 2006

Baby's First Post-Apocalyptic Fiction
What's the difference between
code:
List<string> somelist = PopulateMyList();
List<string> someotherlist = somelist.FindAll(str => str.StartsWith("somthing"));
and
code:
List<string> somelist = PopulateMyList();
List<string> someotherlist = somelist.FindAll(delegate(string str){ return str.StartsWith("somthing"); });
And what's the "=>" format called? It seems to imply a delegate method, but it's a little hard to google, and the MSDN page for Predicate<T> Generic Delegate is somewhat less than helpful here.

mantaworks
May 6, 2005

by Fragmaster
These are lambda expressions. Oreilly says:

quote:

Lambda expressions are designed to provide not only inline delegate definitions, but also a framework for Language-Integrated Query(LINQ).

..

The left operand is a list of zero or more input parameters, and the right operand is the body of the lambda expression.

uXs
May 3, 2005

Mark it zero!
Also, there is no difference between the two. The compiler should compile it exactly the same. The first method is just easier to write and read (once you know what it does.)

TheReverend
Jun 21, 2005

This is a stupid assed question but I can't seem to find out how to write a Dataset to an Excel XLS file in Winforms. Any ideas?

uh zip zoom
May 28, 2003

Sensitive Thugs Need Hugs

hey, I'm displaying data using a gridview, and one of the columns is a datetime, what's the best way to format these date values (mm/dd/yyyy, for example)?

biznatchio
Mar 31, 2001


Buglord

TheReverend posted:

This is a stupid assed question but I can't seem to find out how to write a Dataset to an Excel XLS file in Winforms. Any ideas?

Get a third-party component, or write some simple code to export as a CSV file, which Excel can read.

MORE CURLY FRIES
Apr 8, 2004

uh zip zoom posted:

hey, I'm displaying data using a gridview, and one of the columns is a datetime, what's the best way to format these date values (mm/dd/yyyy, for example)?

If you've got a variable called myDate then you can use myDate.ToShortDateString()

theodop
Dec 30, 2005

rock solid, heart touching
I've been working on a C# program for rollout of our program installations. It consists of two parts: the configuration and files set up on a hidden share on a site's server, and the executable run on the local machine. The program uses robocopy to grab different directories from the server as required for whatever purpose the workstation is filling.

Now, the servers are on our domain, as are most, but not all, of our local workstations. The problem is that there are a number of local workstations that do not run on the domain. Since the servers and the workstations do not share any non-domain logins, this means that on the non-domain workstations I cannot access the files to copy from the server.

Is there any way, or any program, that will allow me to specify different source and destination logins for copying files? I would rather solve this problem using the existing logins as there's quite a lot of work in adding (and justifying) logins or open shares on almost 50 servers.

EDIT: map a network drive, problem solved :)

theodop fucked around with this message at 07:10 on Apr 15, 2008

Richard Noggin
Jun 6, 2005
Redneck By Default

theodop posted:

domain/workgroup stuff

Or just supply fully qualified credentials in the form of domain\username.

ray2k
Feb 7, 2004

Puppet scum beware!

uh zip zoom posted:

hey, I'm displaying data using a gridview, and one of the columns is a datetime, what's the best way to format these date values (mm/dd/yyyy, for example)?
If you're using data-binding, on the BoundField/TemplateField/whateverField, set HtmlEncode to false, and DataFormatString to {0:MM/dd/yyyy}

cadmium
Feb 16, 2002

Just 'aving a laff...
Here's a question, I'm trying to use XmlSerializer on a class hierarchy. I'm trying to produce some simple xml for a 3rd party api. What I'm getting is close, but the XmlSerializer insists on junking it up with xsi/namespace crap:

code:
<Envelope [b]xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"[/b]>
  [b]<_body xsi:type="LoginBody">
    <Login xsi:type="LoginContent">...</Login>
  </_body>[/b]
  <Body [b]xsi:type="LoginBody"[/b]>
    <Login [b]xsi:type="LoginContent"[/b]>...</Login>
  </Body>
</Envelope>
I don't need to deserialize it, just fire and forget. How can I get stop it from adding that extra junk?

TheReverend
Jun 21, 2005

biznatchio posted:

Get a third-party component, or write some simple code to export as a CSV file, which Excel can read.

I can do the CSV thing, it just seems like a hacky last resort. Any ideas for free or low cast third party libraries?

uh zip zoom
May 28, 2003

Sensitive Thugs Need Hugs

double post, sorry

uh zip zoom fucked around with this message at 19:00 on Apr 15, 2008

uh zip zoom
May 28, 2003

Sensitive Thugs Need Hugs

uh zip zoom posted:

yes, but can it sort when you click the header?

Here's my code, if it helps. Clicking the header has no effect.

code:
<asp:BoundField DataField="SubmittedDate" HtmlEncode="false"
 DataFormatString="{0:MM/dd/yyyy}" HeaderText="Date Submitted" ReadOnly="true" SortExpression="SubmittedDate" /> 

JoeNotCharles
Mar 3, 2005

Yet beyond each tree there are only more trees.

TheReverend posted:

I can do the CSV thing, it just seems like a hacky last resort. Any ideas for free or low cast third party libraries?

There's nothing reliable, because the Excel file format is a bastard. (Here's why.)

Your choices are: invoke Excel through COM interop or whatever they're calling it these days, add your data to a worksheet and then tell Excel to save the worksheet; find some third-party worksheet format that's simple enough to have tools that work with it, and also supported by Excel (so, probably Quattro Pro or some other also-ran); use CSV. If you're just storing data and don't need to set up formulas or anything, CSV is a no-brainer.

EDIT: the link I posted above suggests using the Lotus 1-2-3 format, .WK1. I believe Office 2008 dropped support for that.

JoeNotCharles fucked around with this message at 19:16 on Apr 15, 2008

wwb
Aug 17, 2004

TheReverend posted:

This is a stupid assed question but I can't seem to find out how to write a Dataset to an Excel XLS file in Winforms. Any ideas?

See this article I wrote: http://www.sitepoint.com/blogs/2006/08/22/making-excel-the-carlosag-way/

Not quite an excel file, but much better than CSV.

PS: Another good option, if you have .NET 3.0 on the clients, is to create Excel 2007 workbooks. There is a pure managed API that is reputedly very good, or at least usable.

gibbed
Apr 10, 2006

cadmium posted:

Here's a question, I'm trying to use XmlSerializer on a class hierarchy. I'm trying to produce some simple xml for a 3rd party api. What I'm getting is close, but the XmlSerializer insists on junking it up with xsi/namespace crap:

code:
<Envelope [b]xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"[/b]>
  [b]<_body xsi:type="LoginBody">
    <Login xsi:type="LoginContent">...</Login>
  </_body>[/b]
  <Body [b]xsi:type="LoginBody"[/b]>
    <Login [b]xsi:type="LoginContent"[/b]>...</Login>
  </Body>
</Envelope>
I don't need to deserialize it, just fire and forget. How can I get stop it from adding that extra junk?
Doesn't the XmlSerializer have options you can use on creation or use of the objects that define formatting?

cadmium
Feb 16, 2002

Just 'aving a laff...

gibbed posted:

Doesn't the XmlSerializer have options you can use on creation or use of the objects that define formatting?

Not that I can find. There was a hack involving XmlSerializerNamespaces for .NET1 but it actually makes things worse in .NET 2+.

wwb
Aug 17, 2004

Yeah, I have hit this a few times and have not found an elegant solution. My inelegant solution was doing a little string.Replace() on the post-serialized stuff before sending it off for processing. Definitely a hack, but it seems to work pretty well so long as the API is locked in.

Another reasonable option would be to, presuming the stuff is not too complex, write your own serialization, either using XmlTextWriter or by explicitly implementing IXmlSerializable. That should put you back in the control at the cost of having to write more code.

I hate loving xml namespaces and poo poo that honors them.

cadmium
Feb 16, 2002

Just 'aving a laff...

wwb posted:

Yeah, I have hit this a few times and have not found an elegant solution. My inelegant solution was doing a little string.Replace() on the post-serialized stuff before sending it off for processing. Definitely a hack, but it seems to work pretty well so long as the API is locked in.

Another reasonable option would be to, presuming the stuff is not too complex, write your own serialization, either using XmlTextWriter or by explicitly implementing IXmlSerializable. That should put you back in the control at the cost of having to write more code.

I hate loving xml namespaces and poo poo that honors them.

I hate serialization. I fought binary serialization last fall and now I'm fighting xml serialization.

I've currently been implementing a custom XmlTextWriter, but it's pretty hackey and I'm still trying to get rid of the <_body> crap.

Anonymous Name
Apr 25, 2006

by Fragmaster
Man, .NET event handling is complete poo poo. I was trying to figure why merely removing a handler from an event 10,000 times took 8 seconds. Finally realized it's because of the size of the listener list; removals must be an O(N) operation! That's absurd.

Anyone know of a better built-in method for registering large numbers of event callbacks, or do I just have to do it myself? I'm guessing the native implementation uses the List class, which is actually a dynamic array and not a linked list. That would speed up insertions but of course makes removals (that aren't from the end) absurdly slow.

csammis
Aug 26, 2003

Mental Institution

Anonymous Name posted:

Man, .NET event handling is complete poo poo. I was trying to figure why merely removing a handler from an event 10,000 times took 8 seconds. Finally realized it's because of the size of the listener list; removals must be an O(N) operation! That's absurd.

quote:

I was trying to figure why merely removing a handler from an event 10,000 times took 8 seconds.

quote:

removing a handler from an event 10,000 times

What in the hell are you doing that this is a requirement? :psyduck:

Also no, events are part of the C# language. If you want to get clever, you need to maintain your own delegate lists. That's what I ended up doing when I implemented priority-based event handlers for shaim.

Pivo
Aug 20, 2004


Can anyone think of a reason why WPF would stop updating the screen? After running for an hour or two, my digital signage application stops refreshing the screen. The app is still running in the background, updating the registry, firing off timer events, etc (or our watchdog app would realize it's hung). Minimizing and maximizing brings it right back. It's as if the WPF render thread is getting stuck on something. When it comes back up, though, it runs pathetically slow and uses up 99% CPU until I restart the app.

Profiling the app gives no useful data. Neither does debugging it; attaching a debugger causes the rendering to work again but again 99% CPU. I am totally at my wit's end. I can't figure out what the gently caress is causing this. I'm starting to hate WPF.



edit: What if it's a VRAM issue, and minimizing/maximizing has WPF re-start rendering the window in Software mode?? I'm watching VRAM in Perforator and it just keeps going up. I'm going to assume video RAM isn't garbage collected the way system RAM is. What could be causing a video RAM leak?

edit2: VRAM hits a peak and then starts coming down. I guess it's not that.

edit3: The peak the VRAM usage hits keeps increasing. First 95MB, now 99MB. We've only got 128. Also the number of software intermediate render targets is slowly increasing. Goddamn goddamn goddamn this is what happens when you put a simple API on a very complex system, it's impossible to understand what the heck is actually going on.

Pivo fucked around with this message at 19:59 on Apr 16, 2008

wwb
Aug 17, 2004

csammis posted:

What in the hell are you doing that this is a requirement? :psyduck:

Also no, events are part of the C# language. If you want to get clever, you need to maintain your own delegate lists. That's what I ended up doing when I implemented priority-based event handlers for shaim.

I second this sentiment. 10,000 listeners to a single event screams architecture issue.

quote:

I hate serialization. I fought binary serialization last fall and now I'm fighting xml serialization.

I've currently been implementing a custom XmlTextWriter, but it's pretty hackey and I'm still trying to get rid of the <_body> crap.

That is interesting--can you post the serialization code. My experiences with XmlTextWriter generally indicate that it, well, writes what you tell it to write.

Anonymous Name
Apr 25, 2006

by Fragmaster
I have 10,000 icons (for example) in a 3D world, each of which may be associated with a more abstract object that has certain properties. When those properties change, the icons need to be notified so they can handle it. Not all icons would need to handle it.

So the abstract object has an event for when one of its properties changes, and for when it's removed. The icons set up listeners when they become associated with that object. (They don't actually belong to the abstract and can change whom they associate with.)

When I delete all those icons, then I have 10,000 handlers I'm removing. But there could be other objects that are still using those events so I can't simply dump the entire event handler list or anything.

uXs
May 3, 2005

Mark it zero!

cadmium posted:

Here's a question, I'm trying to use XmlSerializer on a class hierarchy. I'm trying to produce some simple xml for a 3rd party api. What I'm getting is close, but the XmlSerializer insists on junking it up with xsi/namespace crap:

code:
<Envelope [b]xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"[/b]>
  [b]<_body xsi:type="LoginBody">
    <Login xsi:type="LoginContent">...</Login>
  </_body>[/b]
  <Body [b]xsi:type="LoginBody"[/b]>
    <Login [b]xsi:type="LoginContent"[/b]>...</Login>
  </Body>
</Envelope>
I don't need to deserialize it, just fire and forget. How can I get stop it from adding that extra junk?

Weird. When I try to serialize things, it just puts <?xml version="1.0" encoding="utf-8"?> and <RootElementNameHere xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> at the top, and that's it. Can you post the code you use to serialize, and the class you're serializing ?

dwazegek
Feb 11, 2005

WE CAN USE THIS :byodood:

Anonymous Name posted:

I have 10,000 icons (for example) in a 3D world, each of which may be associated with a more abstract object that has certain properties. When those properties change, the icons need to be notified so they can handle it. Not all icons would need to handle it.

So the abstract object has an event for when one of its properties changes, and for when it's removed. The icons set up listeners when they become associated with that object. (They don't actually belong to the abstract and can change whom they associate with.)

When I delete all those icons, then I have 10,000 handlers I'm removing. But there could be other objects that are still using those events so I can't simply dump the entire event handler list or anything.

Can't you just leave the event handlers attached (and possibly do nothing if the icon's already deleted), and let the garbage collector clean things up? Unless I'm mistaken, the attached event handlers won't keep the icons from being garbage collected, so you don't have to manually unhook them.

Pivo
Aug 20, 2004


dwazegek posted:

Unless I'm mistaken, the attached event handlers won't keep the icons from being garbage collected, so you don't have to manually unhook them.

I believe you are mistaken.

http://blogs.msdn.com/jgoldb/default.aspx

quote:

This leak is triggered because the child window (Window2) has a reference (it registered to an event) to Window1 TextBox1 which remains alive causing the Window2 object and its element tree to remain alive.

In general, if you do this:

Foo.SomeEvent += new EventHandler(Bar.SomeMethod)

Then when you done using Bar, but you are still using Foo then Bar will still remain alive as well. Not what you might have expected.

Anonymous Name
Apr 25, 2006

by Fragmaster

dwazegek posted:

Can't you just leave the event handlers attached (and possibly do nothing if the icon's already deleted), and let the garbage collector clean things up? Unless I'm mistaken, the attached event handlers won't keep the icons from being garbage collected, so you don't have to manually unhook them.
That won't work for various reasons -- an example being that the garbage collector will never clean things up because the event handler keeps the object alive.

I coded my own solution just now using a SortedDictionary<int,Function>. When an object adds an event handler, it has to remember an int key now (that key is what's passed back to remove the object) but I measured the time it took to add 10,000 event handlers, then fire the event, then remove those 10,000 handlers.

.NET event: 2.92 seconds
My approach: 0.047 seconds

Less than 1/20 of a second compare to 3 seconds! SortedDictionaries use a bunch of memory, and my approach is less convenient due to the key, but the speed increase is ridiculous.

csammis
Aug 26, 2003

Mental Institution

Anonymous Name posted:

.NET event: 2.92 seconds
My approach: 0.047 seconds

Less than 1/20 of a second compare to 3 seconds! SortedDictionaries use a bunch of memory, and my approach is less convenient due to the key, but the speed increase is ridiculous.

Sounds about right, and you pointed out the reason that I suspect this behavior exists: it's optimized for handler adds, not removals, and 10000 handlers is particularly insane. I'm not saying your situation isn't valid, but drat.

edit: Why not use the handling object itself as the SortedDictionary key? It would remove the requirement of having to store some random integer as the key, at any rate. Then you get someObject.AddHandler(object, Delegate); and someObject.RemoveHandler(object);

csammis fucked around with this message at 20:08 on Apr 16, 2008

dwazegek
Feb 11, 2005

WE CAN USE THIS :byodood:

csammis posted:

edit: Why not use the handling object itself as the SortedDictionary key? It would remove the requirement of having to store some random integer as the key, at any rate. Then you get someObject.AddHandler(object, Delegate); and someObject.RemoveHandler(object);

The key of a SortedDictionary has to implement either IComparable, or IComparable<T> (or a custom comparer has to be supplied).

You can also try SortedList, it should use less memory, but the add/remove operations are slower (according to MSDN).

Pivo posted:

I believe you are mistaken.
Yep, looks like I am.

If an object A has an event that B's registered to, then B won't be collected while A's around, but A can be collected while B's around. I thought it worked both ways. Well, looks like I'll have some work to do tomorrow.

csammis
Aug 26, 2003

Mental Institution

dwazegek posted:

The key of a SortedDictionary has to implement either IComparable, or IComparable<T> (or a custom comparer has to be supplied).

That's right. Since he's got such exquisite control over his event handlers, I'm assuming he can implement one of the IComparables. It may be done anyway, with 10000 objects they may be getting stored in a list and being searched for at some point.

Anonymous Name
Apr 25, 2006

by Fragmaster
You can't implement IComparable in a delegate unless I'm missing something. And you can't use the hash code (of the target and the method) as a unique key either because collisions do occur. So my event is an instance of an actual object, with a counter that gets incremented each time a handler is added (but is never decremented, guaranteeing a unique value for each added handler). This value is used as the key in the dictionary.

cadmium
Feb 16, 2002

Just 'aving a laff...

uXs posted:

Weird. When I try to serialize things, it just puts <?xml version="1.0" encoding="utf-8"?> and <RootElementNameHere xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> at the top, and that's it. Can you post the code you use to serialize, and the class you're serializing ?

One thing that is making things trickier is that I'm serializing inherited classes.

JoeNotCharles
Mar 3, 2005

Yet beyond each tree there are only more trees.

Anonymous Name posted:

So my event is an instance of an actual object, with a counter that gets incremented each time a handler is added (but is never decremented, guaranteeing a unique value for each added handler).

Until it overflows. If you're using objects in bunches of 10000, I wouldn't rule that out.

Anonymous Name
Apr 25, 2006

by Fragmaster

JoeNotCharles posted:

Until it overflows. If you're using objects in bunches of 10000, I wouldn't rule that out.
I already ruled it out; four billion is a lot. I can always just make it a long if I really think it's necessary...

dwazegek
Feb 11, 2005

WE CAN USE THIS :byodood:
code:
//1:
var result = stream.BeginWrite(bytes, 0, bytes.Length, null, null);
stream.EndWrite(result);

//2:
stream.Write(bytes, 0, bytes.Length);

Is there any reason why 1 would leak memory, and 2 wouldn't?

No exceptions are being thrown, and there are no other differences. It doesn't matter how I call the asynchronous operation (callback, waiting for the AsyncResult's waithandle, or immediately calling EndWrite).

edit:
The amount of leaked memory doesn't seem to coincide with the bytes that are written.

dwazegek fucked around with this message at 12:03 on Apr 18, 2008

Uziel
Jun 28, 2004

Ask me about losing 200lbs, and becoming the Viking God of W&W.
I'm just learning .net and have run into something I can't figure out. Using asp.net to connect to an access database. The access database has a few tables, and I have some drop down forms that allow you to filter the data on the main table.

When you click on an item once filtered, it selects the data from the corresponding table using as an example "select * from other table where code = ?", the code is supplied via the browser string, etc.

It's all done except for the last page, which is slightly different than the others. Two variables are sent in the address bar, and depending on which data is supplied a different select statement is used.

This is an on load event:
code:
 Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        If Request.QueryString("prot") = "JD" Then
            FormViewDataSource.SelectCommand = "SELECT PackageName, Channel, PackageCode FROM DACPkgs WHERE Pkgcode = ?"
        ElseIf Request.QueryString("prot") = "SD" Then
            FormViewDataSource.SelectCommand = "SELECT PackageName, Channel, PackageCode FROM DNCSPkgs WHERE Pkgcode = ?"
        ElseIf Request.QueryString("prot") = "TD" Then
            FormViewDataSource.SelectCommand = "SELECT PackageName, Channel, PackageCode FROM HITSPkgs WHERE Pkgcode = ?"
        Else
            Response.Write("See Code details for more information")
        End If
        FormViewDataSource.SelectParameters.Clear()
        FormViewDataSource.SelectParameters.Add(New QueryStringParameter("?", "pkgcode"))
        FormView1.DataBind()
I ran it through debug and everything seems to work under the SelectParameters.

This is the error I get:
code:
Exception Details: System.Data.OleDb.OleDbException: No value given for one or more required parameters.

Source Error: 


Line 16:         FormViewDataSource.SelectParameters.Clear()
Line 17:         FormViewDataSource.SelectParameters.Add(New QueryStringParameter("?", "pkgcode"))
Line 18:         FormView1.DataBind()
Line 19: 
Line 20: 
 
Any ideas?

Adbot
ADBOT LOVES YOU

uXs
May 3, 2005

Mark it zero!

Uziel posted:

This is the error I get:
code:
Exception Details: System.Data.OleDb.OleDbException: No value given for one or more required parameters.

Source Error: 


Line 16:         FormViewDataSource.SelectParameters.Clear()
Line 17:         FormViewDataSource.SelectParameters.Add(New QueryStringParameter("?", "pkgcode"))
Line 18:         FormView1.DataBind()
Line 19: 
Line 20: 
 
Any ideas?

Is "pkgcode" supposed to be in quotes ? It looks like it should be a variable and you accidently put quotes around it.

  • Locked thread