C# School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become a C# Expert!

Join 307,149 C# Programmers for FREE! Get instant access to thousands of C# experts, tutorials, code snippets, and more! There are 1,716 people online right now. Registration is fast and FREE... Join Now!




Breaking the code. Fun ways to stump your PC.

 

Breaking the code. Fun ways to stump your PC.

papuccino1

22 May, 2009 - 03:08 PM
Post #1

C# Programmer
Group Icon

Joined: 2 Mar, 2008
Posts: 945



Thanked: 33 times
Dream Kudos: 50
My Contributions
Hey there. I thought it would be fun if you guys shared code that "broke" your PC. For instance a stack overflow, etc.

This particular glitch in my code was found in approx. 6 seconds but was 100% new to me to be exact. Quite exciting stuff.

Use this in a part of your code.

csharp
for (int i = 0; i <= 9; i++)
{
int x = Randomer.Next(1, 8);
System.Threading.Thread.Sleep(20);
if (!(GeneratedNumbers.Contains(x)))
{
GeneratedNumbers[i] = x;
}
else
i--;
}


This little algorithm was made there were no repeated random numbers in my int array. Try to find out what's wrong with it. xD

Lesson learned I say, because neither the compiler nor Windows itself threw any sort of error. The program just froze there in space and time, looking (fruitlessly) for a number that isn't repeated.

Share some more!

User is offlineProfile CardPM
+Quote Post


masteryee

RE: Breaking The Code. Fun Ways To Stump Your PC.

23 May, 2009 - 08:02 PM
Post #2

D.I.C Regular
***

Joined: 16 May, 2009
Posts: 269



Thanked: 38 times
My Contributions
While it's possible for your loop to become infinite prior to i = 8, your loop definitely becomes an infinite loop around i = 8 because all 8 numbers are already in your array, so your loop ends up infinitely performing an i-- for every i++, so your iteration index never moves on.

Here's a random glitch off the top of my head. Assuming I have a simple form with a TextBox and Button and nothing more, why does the following freeze your program:

C#

private void button_Click(object sender, EventArgs e)
{
Invoke(new Action(() => textBox.Text = "You've won a million dollars!"));
}


The Visual Studio debugger may actually tell you the answer, lol. If it does, then tell me the theory behind why it freezes the program.
User is offlineProfile CardPM
+Quote Post

masteryee

RE: Breaking The Code. Fun Ways To Stump Your PC.

28 May, 2009 - 10:56 AM
Post #3

D.I.C Regular
***

Joined: 16 May, 2009
Posts: 269



Thanked: 38 times
My Contributions
Oops, I finally tested my code and it did not cause a deadlock like I thought it would. What the hell's the point of InvokeRequired then if you can call Invoke from any thread? Sorry everyone.
User is offlineProfile CardPM
+Quote Post

AdamSpeight2008

RE: Breaking The Code. Fun Ways To Stump Your PC.

30 May, 2009 - 09:09 AM
Post #4

The Bandido Coder
Group Icon

Joined: 29 May, 2008
Posts: 2,734



Thanked: 160 times
Dream Kudos: 3925
Expert In: vb.net, LINQ

My Contributions
A one line program that is hard to kill.
Warning!! Requires a restart to stop.
CODE

Module KillMeIfYouCan
Sub Main()
  Process.Start(System.Windows.Forms.Application.ExecutablePath)
End Sub
End Module

User is offlineProfile CardPM
+Quote Post

jacobjordan

RE: Breaking The Code. Fun Ways To Stump Your PC.

2 Jul, 2009 - 07:59 PM
Post #5

class Me : Perfection
Group Icon

Joined: 11 Jun, 2008
Posts: 1,493



Thanked: 66 times
Dream Kudos: 1725
My Contributions
QUOTE(AdamSpeight2008 @ 30 May, 2009 - 11:09 AM) *

A one line program that is hard to kill.
Warning!! Requires a restart to stop.
CODE

Module KillMeIfYouCan
Sub Main()
  Process.Start(System.Windows.Forms.Application.ExecutablePath)
End Sub
End Module


I prefer this
csharp

static void Main(string[] args)
{
while (true)
{
System.Diagnostics.Process.Start(System.Windows.Forms.Application.ExecutablePath);
}
}


User is offlineProfile CardPM
+Quote Post

Locke

RE: Breaking The Code. Fun Ways To Stump Your PC.

4 Jul, 2009 - 07:06 PM
Post #6

Treasure Hunter
Group Icon

Joined: 20 Mar, 2008
Posts: 4,023



Thanked: 299 times
Dream Kudos: 325
Expert In: Java

My Contributions
Alright, AdamSpeight2008 and jacobjordan...you stumped me. I'm too lazy to Google it (tongue.gif), so what does the System.Diagnostics.Process.Start(System.Windows.Forms.Application.ExecutablePath); do?

This post has been edited by Locke: 4 Jul, 2009 - 07:07 PM
User is offlineProfile CardPM
+Quote Post

AdamSpeight2008

RE: Breaking The Code. Fun Ways To Stump Your PC.

5 Jul, 2009 - 07:35 AM
Post #7

The Bandido Coder
Group Icon

Joined: 29 May, 2008
Posts: 2,734



Thanked: 160 times
Dream Kudos: 3925
Expert In: vb.net, LINQ

My Contributions
System.Diagnostics.Process.Start()Starts a new process.
System.Windows.Forms.Application.ExecutablePath The location of the exe of this program.
In my case it starts a new instance of the program and runs it, in jacobjordan it creates a multiple instances (Exponential growth)

User is offlineProfile CardPM
+Quote Post

Locke

RE: Breaking The Code. Fun Ways To Stump Your PC.

5 Jul, 2009 - 10:04 AM
Post #8

Treasure Hunter
Group Icon

Joined: 20 Mar, 2008
Posts: 4,023



Thanked: 299 times
Dream Kudos: 325
Expert In: Java

My Contributions
That's what I figured, since it had to keep the computer occupied and running itself silly somehow.

Yay for useless (if only for fun smile.gif) process calls! laugh.gif

This post has been edited by Locke: 5 Jul, 2009 - 10:04 AM
User is offlineProfile CardPM
+Quote Post

firexware

RE: Breaking The Code. Fun Ways To Stump Your PC.

7 Jul, 2009 - 09:38 AM
Post #9

New D.I.C Head
*

Joined: 6 Jul, 2009
Posts: 48



Thanked: 2 times
My Contributions
CODE
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Application.DoEvents() 'let it show the window
        Application.Restart()
    End Sub

i find that more annoying then starting hundreds of forms
User is offlineProfile CardPM
+Quote Post

RudiVisser

RE: Breaking The Code. Fun Ways To Stump Your PC.

31 Jul, 2009 - 03:55 AM
Post #10

.. does not guess solutions
Group Icon

Joined: 5 Jun, 2009
Posts: 1,891



Thanked: 139 times
Dream Kudos: 125
Expert In: PHP, MySQL, HTML, CSS, C#

My Contributions
One of our services has 2 components that monitor each other, so if one goes down, the other would restart it instantly, and vice versa.

A big problem arose when I changed the .exe name and it constantly thought it was not started biggrin.gif biggrin.gif
User is offlineProfile CardPM
+Quote Post

doucet.damon

RE: Breaking The Code. Fun Ways To Stump Your PC.

6 Aug, 2009 - 04:53 PM
Post #11

New D.I.C Head
*

Joined: 6 Aug, 2009
Posts: 25



Thanked: 2 times
My Contributions
A funny little thing I made for a friend was to create 4 forms, where each one had the size of 1/2 the width of the screen by 1/2 the height of the screen. In the Main method, drop the Application.Run() call and replace it with just initializing and showing the 4 forms; position one in each corner of the screen. Turn the "Show In Taskbar" property to false, the "Top Most" to true, and override the CreateParams property on the form so that it doesn't show in Alt Tab (just to be nice looking). In Main() do a while(true) to loop through changing the background colors of the forms to something different (incrementing each's value in a predefined array), so it flashes like crazy, and the only way you can get out of it (without restarting) is if your Task Manager has "Always on Top" checked.
User is offlineProfile CardPM
+Quote Post

Donnie1581

RE: Breaking The Code. Fun Ways To Stump Your PC.

7 Nov, 2009 - 04:20 AM
Post #12

D.I.C Head
**

Joined: 5 Nov, 2009
Posts: 56



Thanked: 2 times
My Contributions
QUOTE(doucet.damon @ 6 Aug, 2009 - 04:53 PM) *

A funny little thing I made for a friend was to create 4 forms, where each one had the size of 1/2 the width of the screen by 1/2 the height of the screen. In the Main method, drop the Application.Run() call and replace it with just initializing and showing the 4 forms; position one in each corner of the screen. Turn the "Show In Taskbar" property to false, the "Top Most" to true, and override the CreateParams property on the form so that it doesn't show in Alt Tab (just to be nice looking). In Main() do a while(true) to loop through changing the background colors of the forms to something different (incrementing each's value in a predefined array), so it flashes like crazy, and the only way you can get out of it (without restarting) is if your Task Manager has "Always on Top" checked.



Awesome, I'm going to screw with some people using this!
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/21/09 04:21PM

Live C# Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

C# Tutorials

Reference Sheets

C# Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month