473,382 Members | 1,736 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Application hang after screensaver

Hello,

I have strange problem. I let my application work (it tests in loop
with 3sec brakes if it's possible to connect to remote pc /by ssh/)
and do nothing until screensaver activates. After it activates I move
mouse to get back to Windows. And now:
1. When I have screensaver protected with a password, whole
application hangs. It even blocks taskbar.
2. When I have screensaver without password, everything is just fine.
That's not the end. I've just found that, when I change my screen
settings (for example resolution, or wallpaper) application hangs too
(after confirming changes).

If you want me to post some code, please say which part of it I should
paste. It's quite big, so I don't want to spam too much.

Any ideas or articles about that issue would be very helpful.

Thanks in advice,
Mateusz M. Zająkała

Oct 2 '07 #1
6 2118
I've just found that problem occure only when I start my application
by desktop shortcut.
Started 'normal' way behaves just fine.

Here's the way I create desktop shortcut:

private void desktopShortcut_Click(object sender, EventArgs e)
{
string desktopPath =
Environment.GetFolderPath(Environment.SpecialFolde r.DesktopDirectory);

if (File.Exists(desktopPath + "/WokandaTools.lnk") == true)
{
MessageBox.Show("Shortcut already exists.", "Msgbox name",
MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
Shortcut.CreateShortcut();
File.Move(AppDomain.CurrentDomain.BaseDirectory + "\
\applicationName.lnk", desktopPath + "\\applicationName.lnk");
MessageBox.Show("Shortcut created.", "Msgbox name",
MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}

public static void CreateShortcut()
{
string app = AppDomain.CurrentDomain.BaseDirectory +
@"\applicationName.exe";
try
{
IWshShell_Class shell = new IWshShell_ClassClass();
char znak = '.';
string appName = app.Remove(app.LastIndexOf(znak), 4);
IWshShortcut_Class shortcut = shell.CreateShortcut(appName +
".lnk") as IWshShortcut_Class;
shortcut.TargetPath = app;
shortcut.IconLocation = app + ",0";
shortcut.Save();
}
catch (COMException ex)
{
Console.WriteLine(ex.Message);
}
}

Oct 2 '07 #2
By 'normal' start I ment debug in VS. Started by .exe hangs everytime
I change my screen settings.
I'm sorry for little chaos I made, but I'm totaly confused. First time
get problem like this and I just can't find any answers or simillar
problems over net.

I would be gratefull for any ideas or help.

Oct 2 '07 #3
I've found the problem. It's little bit tricky for me, I'm very far
from expert in thread programming...

In thread method I'm checking if list of pc's (ip numbers) has
changed.

public void ThreadProc()
{
...
ipList = updateIpList();
...
}

public static List<stringupdateIpList()
{
List<stringnewIpList = null;

mainForm mf = new mainForm();
newIpList = mf.getIpList();
mf.Dispose(); //without this dispose applicaction hangs, after
adding this line it works good.

return newIpList;
}

Perhaps it's not too 'good-looking'. In main form I use getIpList()
function, so I thought I'll just refer to it. Perhaps I should repeat
declaration of that function in monitor class? Anyway with dispose it
works just fine.
But that don't answer me, why application hangs when i don't destruct
main form constructor. Any ideas?

Oct 3 '07 #4
ma**************@gmail.com wrote:
[...]
Perhaps it's not too 'good-looking'. In main form I use getIpList()
function, so I thought I'll just refer to it. Perhaps I should repeat
declaration of that function in monitor class? Anyway with dispose it
works just fine.
But that don't answer me, why application hangs when i don't destruct
main form constructor. Any ideas?
I don't know specifically. But note that when the workstation is
locked, there's no desktop for the application to interact with. You
shouldn't be creating a form like that anyway, and it sounds as though
somehow the lack of a desktop causes something to get stuck, maybe
waiting on the processing of a window message that can never happen or
something like that.

Anyway, as I mention above, you shouldn't be creating the form in the
first place. Instantiating a form just because you want to call a
method on the form is very bad. You should only instantiate a form when
you actually want to show a new instance of that form. In all
likelihood you've already got one instance of that form, and that's the
only instance you should ever have.

You didn't post the code for mainForm.getIpList(), but it may not be the
sort of method that really needs to be in the form class in the first
place. The fact that the method works when you call it on a new
instance of the form suggests that there's not actually anything in that
method that uses the data in the form itself.

So, at the very least it seems like you could make the method a static
method, which would allow you to call it without an instance of the
form. It's likely that even better would be to move that method out of
the form class altogether; if it doesn't have anything to do with the
form itself, it's probably better to have it somewhere else (like in
your data management class).

Where to put the method and how to call it are two different issues.
Even if you move it, you'll want to make sure that it's either a static
method, or that you use a pre-existing instance of a class rather than
instantiating a class just so that you can call it.

Pete
Oct 3 '07 #5
On 3 Paź, 18:39, Peter Duniho <NpOeStPe...@NnOwSlPiAnMk.comwrote:
<cut>
Anyway, as I mention above, you shouldn't be creating the form in the
first place. Instantiating a form just because you want to call a
method on the form is very bad.
Ok.
You didn't post the code for mainForm.getIpList(), but it may not be the
sort of method that really needs to be in the form class
Trully? It does not needs to be in mainForm class or monitForm, but...
Is it better to refer to a method that belongs to the same class from
where I want to call it, or create instance of other class where that
method is and then call it? Isn't second method less efficent. I have
to create additional instance of class etc.
So, at the very least it seems like you could make the method a static
method, which would allow you to call it without an instance of the
form.
I wish, but within getIpList() method I use my own made structure
(list of classes) which holds data about pc's. So I can't make
getIpList static.

public List<stringgetIpList()
{
List<stringipList = new List<string>();

for (int i = 0; i < myStructure.Count; i++)
{
ipList.Add(myStructure[i].IpAdress);
}

return ipList;
}
Where to put the method and how to call it are two different issues.
Even if you move it, you'll want to make sure that it's either a static
method, or that you use a pre-existing instance of a class rather than
instantiating a class just so that you can call it.
Exacly. Like I asked isn't it better to hold method in same class from
which I want to call this method? Let's talk about situation when I
can't make my method static or use existing instance to call that
method.

Thank you for help,
Mateusz Zajakala

Oct 5 '07 #6
On 5 Paź, 20:18, Peter Duniho <NpOeStPe...@NnOwSlPiAnMk.comwrote:
And as far as which class the static method is in, the call would be the
same either way. The only real difference here is whether the function
is static or not. A static function is (_very_ slightly) more efficient
because no "this" reference needs to be passed in the call. But which
class a static or instance method exists in is irrelevant as far as
performance goes.

(And frankly, the performance difference between static and instance
methods is so tiny it's not worth consideration IMHO; generally
speaking, whether to make a method static or not should be a design
decision, not a performance decision).
That's what I wanted to know. Thanks for explenation.
you need to fix your code so that it uses an existing instance of
your form class, rather than creating a new one.
That's what I'll do. After your explenation I know exacly where I did
my mistakes and what to do with it.
So thank you for your time and answers.

Mateusz Zajakala

Oct 11 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Christopher Burr | last post by:
I'm trying to set the user's screensaver in the .NET world... In Win32 I could use a combination of setting the screen saver name via the registry and then setting the time and active status...
2
by: DanielB | last post by:
Does anyone know what the command line argumentto launch a screensaver's options/configuration dialog is on Windows XP Pro? From most of the example source code I can find on the web, it would...
0
by: Paul Smith | last post by:
I have been given an unusual task to create a Windows Service to do something periodically to make the screensaver timer reset. We have a general policy of locking computers automatically after 10...
4
by: Paul Smith | last post by:
I have been given an unusual task to create a Windows Service to do something periodically to make the screensaver timer reset. We have a general policy of locking computers automatically after 10...
2
by: wushupork | last post by:
I have written a screensaver application in C# .NET and have noticed that whenever the animation loop is running - CPU usage always spikes up close to 100%. My application uses a paint thread which...
1
by: DanielB | last post by:
Does anyone know what the command line argumentto launch a screensaver's options/configuration dialog is on Windows XP Pro? From most of the example source code I can find on the web, it would...
3
by: Ron Nanko | last post by:
Hi, I'm trying to setup a screensaver via a C# application. What I currently do is this: unsafe public static extern short SystemParametersInfo (int uiAction, int uiParam, int* pvParam, int...
6
by: VMI | last post by:
How difficult is it to develop a screensaver in C#? The screensaver would be composed of several images and each image would be displayed on the screen for a few seconds. The only difficult part...
11
by: TCook | last post by:
Hey All, I was wondering if anyone has done or knows how to use a screen saver within a VB app (i.e. display a running screen saver on a form or child window like the 'Preview' functionality in...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.