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
Vintersorg
Mar 3, 2004

President of
the Brendan Fraser
Fan Club



Thanks! :) We learned basic XSLT in our course (although I am not sure there is much to it to be honest) but applying it for other stuff is kind of fun.

Going to check out the System.ServiceModel.SyndicationFeed.

I got something sort of working with this Ektron system, bit ghetto but it displays titles, links to the "blog" post and all.

Adbot
ADBOT LOVES YOU

Crankit
Feb 7, 2011

HE WATCHES
I checked the OP but it's 3+ years old, and I think there are newer .Nets than that, could someone recommend a book to learn C# from?

wwb
Aug 17, 2004

Vintersorg posted:

Thanks! :) We learned basic XSLT in our course (although I am not sure there is much to it to be honest) but applying it for other stuff is kind of fun.

XSLT isn't fun. Its kind of like loving a retard, without the nut.

aBagorn
Aug 26, 2004

Crankit posted:

I checked the OP but it's 3+ years old, and I think there are newer .Nets than that, could someone recommend a book to learn C# from?

I might get some grief, but I had a great learning experience (albeit from a truly beginner standpoint) with Head First C#

gariig
Dec 31, 2004
Beaten into submission by my fiance
Pillbug

Crankit posted:

I checked the OP but it's 3+ years old, and I think there are newer .Nets than that, could someone recommend a book to learn C# from?

I enjoyed Programming C#

Vintersorg
Mar 3, 2004

President of
the Brendan Fraser
Fan Club



wwb posted:

XSLT isn't fun. Its kind of like loving a retard, without the nut.

As long as you keep it simple it's okay.

Basic poo poo like:

<xsl:if test="position() &lt; 5">
<!-- display news items here -->
</xsl:if>

Anything more complicated and i'd rather use something else.

rolleyes
Nov 16, 2006

Sometimes you have to roll the hard... two?

Crankit posted:

I checked the OP but it's 3+ years old, and I think there are newer .Nets than that, could someone recommend a book to learn C# from?

I've heard reasonable things about Visual C# 2010 Step By Step. It's basically the official Microsoft beginner C# book for .NET 4.

Scaramouche
Mar 26, 2001

SPACE FACE! SPACE FACE!

XSLT is actually really neat from a multi-platform/transformation perspective.

boo_radley
Dec 30, 2005

Politeness costs nothing
Once you stop treating xslt like it should be a programming language it's pretty useful.

Knyteguy
Jul 6, 2005

YES to love
NO to shirts


Toilet Rascal
I'm running into a bit of trouble with a multi-threaded program. I'm getting completely random results (+- 100) with this bit of code:

code:
                Thread.Sleep(400);

                file.Close();

                lock (this)
                {
                    string parsedList = System.IO.File.ReadAllText(@"lists\templist.txt");
                    string[] parsedLines = parsedList.Split(new string[] { "\n" }, StringSplitOptions.RemoveEmptyEntries);
                    try
                    {

                        foreach (string listnumber in parsedLines)
                        {
                            // Display Parsed Lines for end use
                            Thread.Sleep(1);
                            // Call object data from function start
                            address = data.ToString();
                            // Add http if no URL prefix is found
                            if (!address.StartsWith("http://") && !address.StartsWith("https://"))
                            {
                                address = "http://" + address;
                            }

                            if (!address.EndsWith("/"))
                                address = address + "/";

                            // Append data from list
                            address = address + listnumber;
                            address.Trim();

                            [b]finishedHits++;[/b]
                            //ChangeProgressBarMax(progressBarMax);

                            //Thread processThread = new Thread(delegate() { Process(address + " " + listIndex); });
                            //processThread.Start();
                            ThreadPool.QueueUserWorkItem(new WaitCallback(Process), (address + " " + listIndex));
Here's the -very- beginning of the Process thread

code:
 private void Process(object data)
        {
            string getDataInfo = data.ToString();
            string[] dataInfo = getDataInfo.Split(new string[] { " " }, StringSplitOptions.None);

            string address;
            address = dataInfo[0];
            address.Trim();
            string listIndex = dataInfo[1];
            countAllHits++;
            ChangeList(countAllHits, int.Parse(listIndex), 2);
            Thread.Sleep(1);
Variables not matching up: countAllHits, finishedHits

Does anyone have an idea why countAllHits will end up being 9900 +-, when it should be 10,000 on the dot? It's totally screwing up my status update so I don't know when it's finished running :gonk:

e(clarify): finishedHits will be 10,000, countAllHits will not be 10,000. Nearly immediately after finishedHits is incremented, a new threadpool call is made, which nearly immediately increments countAllHits as well.

Knyteguy fucked around with this message at 04:15 on Feb 16, 2012

Eggnogium
Jun 1, 2010

Never give an inch! Hnnnghhhhhh!
Not too familiar with C# threading so I could be wrong, but I think you need to lock around "countAllHits++;". It seems like a single operation but it's actually several (loading the value, incrementing it, and storing it back), so if a thread gets interrupted in the middle of those three steps the value will end up being wonky.

Edit: You should really lock around any operation where a thread changes a variable accessible by other threads. Some classes have this locking baked into their methods but definitely not the primitive value types.

Eggnogium fucked around with this message at 04:16 on Feb 16, 2012

Knyteguy
Jul 6, 2005

YES to love
NO to shirts


Toilet Rascal

Eggnogium posted:

Not too familiar with C# threading so I could be wrong, but I think you need to lock around "countAllHits++;". It seems like a single operation but it's actually several (loading the value, incrementing it, and storing it back), so if a thread gets interrupted in the middle of those three steps the value will end up being wonky.

Edit: You should really lock around any operation where a thread changes a variable accessible by other threads. Some classes have this locking baked into their methods but definitely not the primitive value types.

Thanks that did it :woop: I'll have to lock down the other vars as well, I'm sure that's been causing some issues that I just haven't noticed yet.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

Knyteguy posted:

Thanks that did it :woop: I'll have to lock down the other vars as well, I'm sure that's been causing some issues that I just haven't noticed yet.

If you're doing this just to learn, look into using the Task Parallel Library. It's really powerful and will make your life a hell of a lot easier.

http://msdn.microsoft.com/en-us/library/dd537609.aspx

New Yorp New Yorp fucked around with this message at 04:38 on Feb 16, 2012

Sedro
Dec 31, 2008

Knyteguy posted:

Thanks that did it :woop: I'll have to lock down the other vars as well, I'm sure that's been causing some issues that I just haven't noticed yet.
No offense but it looks like you're totally over your head. That code you posted is full of horrors. You should really learn the threading concepts instead of just sprinkling mutex locks everywhere.

The Interlocked class has methods to perform increment atomically without locking.

Knyteguy
Jul 6, 2005

YES to love
NO to shirts


Toilet Rascal

Sedro posted:

No offense but it looks like you're totally over your head. That code you posted is full of horrors. You should really learn the threading concepts instead of just sprinkling mutex locks everywhere.

The Interlocked class has methods to perform increment atomically without locking.

Thanks I'll take a look at that. I've also used a bit of Parallel.ForEach but the program actually ended up slowing down. Because this is my first 'real' program, I'm not very worried about anything other than it working (which it is, besides some thread issues).

If you think this part is bad though, you would probably get a headache from my regex list parsing :psyduck:.

However besides the Interlocked class, do you mind mentioning a few of these 'horrors' so I can see where I can improve? If you get a chance.

Knyteguy fucked around with this message at 05:29 on Feb 16, 2012

FrantzX
Jan 28, 2007
http://www.albahari.com/threading/ - Threading in C#.

rolleyes
Nov 16, 2006

Sometimes you have to roll the hard... two?

FrantzX posted:

http://www.albahari.com/threading/ - Threading in C#.

Seconding that as something which helped me a lot.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

Knyteguy posted:

Thanks I'll take a look at that. I've also used a bit of Parallel.ForEach but the program actually ended up slowing down. Because this is my first 'real' program, I'm not very worried about anything other than it working (which it is, besides some thread issues).


That's probably because you should really only use Parallel.ForEach when you're trying to parallelize a processor-intensive task. What you're doing isn't heavy at all, so the overhead of creating new threads is outweighing the benefit you get from parallelizing it.

If your goal is to keep the UI thread responsive, use a BackgroundWorker or look into doing your blocking operation asynchronously -- asynchronous programming doesn't necessarily use an additional thread.

PhonyMcRingRing
Jun 6, 2002
I dunno if I'm missing it or not, but does anyone know if Codeplex has some way of generating documentation from code comments? It's a bit rough having to write up all their wiki pages manually.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

PhonyMcRingRing posted:

I dunno if I'm missing it or not, but does anyone know if Codeplex has some way of generating documentation from code comments? It's a bit rough having to write up all their wiki pages manually.

There's ghostdoc, which will generate method/class summaries from the method/class names, and Sandcastle will generate MSDN-style docs. http://sandcastle.codeplex.com/

boo_radley
Dec 30, 2005

Politeness costs nothing
Recommend me a PDF API for c#. Our current tool is years out of date and I have a bunch of web forms that will need archiving in our imaging system, which prefers PDF. A little spend is OK, but free/ OS is preferred.

SixPabst
Oct 24, 2006

Knyteguy posted:

Thanks that did it :woop: I'll have to lock down the other vars as well, I'm sure that's been causing some issues that I just haven't noticed yet.

You should also not lock
code:
this
. Create another object for locking with.

Sub Par
Jul 18, 2001


Dinosaur Gum

FrantzX posted:

http://www.albahari.com/threading/ - Threading in C#.

Wow, this was great. Thank you.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

boo_radley posted:

Recommend me a PDF API for c#. Our current tool is years out of date and I have a bunch of web forms that will need archiving in our imaging system, which prefers PDF. A little spend is OK, but free/ OS is preferred.

PDFSharp!

Sedro
Dec 31, 2008

Ithaqua posted:

PDFSharp!
A warning though: if you are reading exiting PDFs, PdfSharp can't handle some newer ~1.6 or later PDF commands.

boo_radley
Dec 30, 2005

Politeness costs nothing
Oh wow, every PDF generating tool looks 90% the same and it results in tons of ugly as gently caress code. Gonna check out PDFSharp now, looks promising if samey.

Scaramouche
Mar 26, 2001

SPACE FACE! SPACE FACE!

boo_radley posted:

Oh wow, every PDF generating tool looks 90% the same and it results in tons of ugly as gently caress code. Gonna check out PDFSharp now, looks promising if samey.

Let me know what you find out, I did the same research about 2 years ago and came up with nothing that didn't suck rear end or cost far too much for the crap it output (looking at you Adobe).

Zhentar
Sep 28, 2003

Brilliant Master Genius
My research concluded the best option was to print an RTF document to a PDF "printer".

Sab669
Sep 24, 2009

edit; one big giant derp :downs:

Sab669 fucked around with this message at 22:41 on Feb 16, 2012

Sprawl
Nov 21, 2005


I'm a huge retarded sperglord who can't spell, but Starfleet Dental would still take me and I love them for it!

boo_radley posted:

Recommend me a PDF API for c#. Our current tool is years out of date and I have a bunch of web forms that will need archiving in our imaging system, which prefers PDF. A little spend is OK, but free/ OS is preferred.

PFSharp did what i needed which was.

Underlay a background image that is a form and then put text overtop like its printing out properly on the form.

aBagorn
Aug 26, 2004
I suspect I will be very active in this thread and stackoverflow in the near future as I start my dream personal project.

I'm planning on using C# to write a weather simulator, based on input data from the major computer models available for public consumption.


(please tell me I'm not nuts for attempting this)

aBagorn fucked around with this message at 16:02 on Feb 17, 2012

Gravy Jones
Sep 13, 2003

I am not on your side
Are you planning on using it to become a supervillain?

aBagorn
Aug 26, 2004

Gravy Jones posted:

Are you planning on using it to become a supervillain?

Of course.

In reality, no. I just want the program to grab the data from the computer models based on a user inputted date range and then output a simulation of weather conditions (for an inputted location (street address converted to lat/long) ) during that timeframe.

Just your average weather junkie

aBagorn fucked around with this message at 17:14 on Feb 17, 2012

PDP-1
Oct 12, 2004

It's a beautiful day in the neighborhood.
Writing physical simulators is fun, good luck!

Make sure you check out the Task Parallel Library and stuff like Parallel.For before you start. Those tools will let you partition your simulation domain into chunks that can run on different processor cores for maximum speed (and occasionally hilarious bugs if you do it wrong).

Sedro
Dec 31, 2008

Knyteguy posted:

However besides the Interlocked class, do you mind mentioning a few of these 'horrors' so I can see where I can improve? If you get a chance.
Sure.
code:
                Thread.Sleep(400);
There is probably no reason to do this.
code:
                file.Close();
Put this in a using block.
code:

                lock (this)
This is dangerous. You are locking on the object reference of your class. If some other code then does lock(yourObject), it will affect the behavior of your class (likely causing deadlock). To make your classes resilient to this, you should always lock on a private field.
code:
                            address = data.ToString();
                            // Add http if no URL prefix is found
                            if (!address.StartsWith("http://") && !address.StartsWith("https://"))
                            {
                                address = "http://" + address;
                            }

                            if (!address.EndsWith("/"))
                                address = address + "/";

                            // Append data from list
                            address = address + listnumber;
                            address.Trim();
System.Uri will do most of this work for you, better.
code:
                            ThreadPool.QueueUserWorkItem(new WaitCallback(Process), (address + " " + listIndex));

...

 private void Process(object data)
        {
            string getDataInfo = data.ToString();
            string[] dataInfo = getDataInfo.Split(new string[] { " " }, StringSplitOptions.None);

            string address;
            address = dataInfo[0];
            address.Trim();
            string listIndex = dataInfo[1];
Here you are concatenating then parsing a string in order to pass two parameters. Instead you should define a class to hold the parameters, or use something like Tuple<T1, T2>, or just use a closure. Also check out TPL which is easier than using the thread pool directly.

PhonyMcRingRing
Jun 6, 2002
So, I'm releasing my first open source project: Detergent. It's an (almost)unobtrusive cascading dropdown library for MVC3. I spent a fair amount of time trying to make this the easiest thing to use, so it should only take about 5 seconds to get the hang of(I hope!). The jQuery script itself can run independently of the MVC, too.

wwb
Aug 17, 2004

Sweet. Have you made a nuget package? They do your traction wonders . . .

PhonyMcRingRing
Jun 6, 2002

wwb posted:

Sweet. Have you made a nuget package? They do your traction wonders . . .

Not yet, though I'm thinking about it. Probably not jumping on that right away, though.

Nurbs
Aug 31, 2001

Three fries short of a happy meal...Whacko!
*Sob* I had to start work on a Webforms UserControl today. It was a humbling experience.

Actually, it's a 'web part' for Kentico CMS. So there's a couple layers of classes (god knows what they do), but it eventually boils down a UserControl.

So on the ascx I declared a drop down list

code:
<asp:DropDownList runat="server" ID="dropdownlist" AppendDataBoundItems="true" OnSelectedIndexChanged="dropdownlist_selectedindexchanged" />
and in the control setup I put

code:
if (!IsPostBack)
{
   dropdownlist.datasource = getdata();
   dropdownlist.databind();
}
Sounds right, right?

Except, when I enter the dropdownlist_selectedindexchanged event handler, I don't appear to have any viewstate. No, selected index, nada nothing. ViewState is enabled for the dropdownlist, the user control it's container and the page.

I had an identical problem with a Repeater that I did much the same thing to, when I entered a Button click event handler that I wanted to iterate over the repeater with.

What am I forgetting?

Adbot
ADBOT LOVES YOU

aBagorn
Aug 26, 2004
Ok, what do you guys consider to be the best map API, Google or otherwise, for .NET?

  • Locked thread