我的程序看起来像这样:
class Prog
{
BufferedImage offscreen;
KindOfDatabase db;
MyThread thread;
class MyThread extends Thread
{
volatile boolean abort=false;
long lastUpdated;
public void run()
{
try
{
KindOfCursor c = db.iterator();
while(c.getNext())
{
if(abort) break;
//fill a histogram with the data,
// calls SwingUtilities.invokeAndWait every 500ms to
//do something with offscreen and update a JPanel
}
catch(Exception err)
{
err.printStackTrace();
}
finally
{
c.close();
}
}
}
void stopThread()
{
if(thread!=null)
{
thread.abort=true;
thread.join();
thread=null;
}
}
void startThread()
{
stopThread(); …Run Code Online (Sandbox Code Playgroud) $(obj).each(function()
// 1) freeze
// 2) then do something
});
Run Code Online (Sandbox Code Playgroud)
如何在几秒钟内冻结脚本?
CONSTANT = 1000000000000000000
array = (1..CONSTANT).to_a
start = Time.now
array.each do |i|
if 1000 < i < CONSTANT * 9 / 10
elsif i > CONSTANT * 9 / 10
else
end
end
finish = Time.now
puts "Running time: #{finish - start} seconds"
Run Code Online (Sandbox Code Playgroud)
我编写了上面的脚本,试图找出通过重新排序控制分支可以节省多少时间.该脚本在运行后立即冻结我的机器,无法通过CTL + C终止.有人可以指出那里发生了什么吗?
我刚刚开始学习如何在 Delphi XE2 中使用 Indy 10 组件。我从一个将使用命令套接字(TIdCmdTCPServer和TIdCmdTCPClient)的项目开始。我已经完成了所有设置并且客户端连接到服务器,但是在客户端连接之后,服务器发送给客户端的任何命令只会冻结服务器应用程序,直到它最终崩溃并关闭(深度冻结之后)。
项目设置
设置非常简单;有一个小型服务器应用程序和一个小型客户端应用程序,每个应用程序都有其对应的 Indy 命令 tcp 套接字组件。客户端上只有一个命令处理程序。
服务器应用程序
在服务器上,我有一个非常简单的上下文包装器type TCli = class(TIdServerContext),它只包含一个公共属性(继承实际上是 Indy 的要求)。
客户端应用程序
另一方面,客户端工作得很好。它从服务器接收命令并执行其操作。客户端有一个计时器,如果它尚未连接,它会自动连接。当前设置为在应用程序启动 1 秒后尝试连接,如果尚未连接,则每 10 秒继续尝试一次。
问题详情
我能够成功地从服务器向客户端发送一两个命令(客户端正确响应),但服务器在发送命令后几秒钟就死机了。我在服务器上有用于OnConnect、OnDisconnect、OnContextCreated和 的事件处理程序,OnException它们真正做的就是在列表视图中发布日志或处理连接/断开连接对象。
截屏

最后,当客户端应用程序正常关闭时,服务器也会正常退出冻结状态。但是,如果客户端被强制关闭,那么服务器也会被强制关闭。这就是我看到的模式。它发布到登录事件PostLog(const S: String),只需将短消息附加到 TMemo。
我做过两个项目,都遇到了问题。我准备了一个示例项目...
服务器代码(uServer.pas和uServer.dfm)
unit uServer;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, IdContext, IdBaseComponent, IdComponent,
IdCustomTCPServer, IdTCPServer, IdCmdTCPServer, Vcl.StdCtrls, Vcl.Buttons,
Vcl.ComCtrls;
type …Run Code Online (Sandbox Code Playgroud) 我的操作组和开发人员对于为什么会发生这种情况一无所知.基本上,客户端/服务器应用程序的服务器端服务挂起.我们一直在推动新的bugfixed版本并向开发者提供各种日志,但他们无法弄明白.为了使其更难理解,这是一个与客户端上的另一个应用程序密切配合的应用程序.
我不知道我是否在这里做了什么,因为我的windbg经验有限,但这似乎值得一试.谷歌很有前途,但大多数游戏玩家都没有提供更多信息......
我在转储开始时发现了这一点:
警告:odbccp32与comctl32重叠.警告:odbc32重叠odbccp32警告:odbc32重叠comctl32 .............警告:mswsock重叠FWPUCLNT .......警告:winsta重叠winnsi.警告:ntlanman重叠drprov ....警告:srvcli重叠netapi32警告:wkscli重叠srvcli ..........警告:ncrypt重叠schannel.警告:nlaapi与ncrypt重叠.警告:NapiNSP重叠nlaapi ....警告:rsaenh重叠了cryptsp
而且有点低:
OVERLAPPED_MODULE:'odbc32'和'odbccp32'重叠的地址区域
这是完整的!analyze -v转储:
Microsoft (R) Windows Debugger Version 6.2.8400.0 AMD64
Copyright (c) Microsoft Corporation. All rights reserved.
Loading Dump File [C:\debug\MES\PLSMES.dmp]
User Mini Dump File: Only registers, stack and portions of memory are available
Symbol search path is: srv*c:\symbols*c:\windows\symbols*http://msdl.microsoft.com/download/symbols
Executable search path is:
Windows 7 Version 7601 (Service Pack 1) MP (16 procs) Free x64
Product: Server, suite: TerminalServer SingleUserTS
Machine Name:
Debug session time: Thu Jun 14 10:37:01.000 2012 …Run Code Online (Sandbox Code Playgroud) 我正在制作一个上面模式的2D Zombie Shooter,我遇到了一些线程问题.这是交易.每当我按下太空时,我都会让角色射出一颗子弹.问题是,如果你持有空间,它会射击一个,然后暂停,然后射出很多子弹.有很多方法可以解决这个问题,但我希望这样,因为它为未来的拍摄速度变化留出了空间.这是导致问题的线程的代码:
package threads;
import Game.GameCore;
public class Shoot extends GameCore implements Runnable {
/**
* WHEN I START THIS THREAD, THE ENTIRE GAME FREEZES, AND I DO NOT KNOW
* WHY... NEED TO FIX. IT DOES NOT FIX THE PROBLEM TO TAKE OUT THE "SHOOT"
* OR THE "SLEEP"...
*/
public void run() {
while (shooting && gameRunning) { // shooting is made true when space is
// pressed, and set false when space
// is released. gameRunning …Run Code Online (Sandbox Code Playgroud) 有没有一种方法可以冻结iOS版Sprite Kit中的粒子节点?基本上将粒子节点中的每个粒子精确地冻结在它们所在的位置。
我正在开发一个与服务器通信的应用程序。
thread = new Thread(new ThreadStart(ClientStart));
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
private void ClientStart()
{
tcpClient = new TcpClient(ip,3000);
stream = tcpClient.GetStream();
while (true) {
stream.Read(...);
PrintMessage(...);
.....
}
}
private void PrintMessage(LogWin w, string msg)
{
DateTime dt = DateTime.Now;
w.GetMessageBox().Dispatcher.BeginInvoke(DispatcherPriority.Input,new Action(()=>w.GetMessageBox()
.AppendText(String.Format("{0:d/M/yyyy HH:mm:ss}", dt) + " : " + msg)));
}
Run Code Online (Sandbox Code Playgroud)
稍后我需要将结果打印到消息框。我知道我必须使用 Dispatcher,因为我在另一个线程中工作,但是即使我使用 beginInvoke 方法,我的应用程序也会冻结。
根据谢里丹的回答进行编辑:
现在我得到:WindowsBase.dll 中发生类型为“System.InvalidOperationException”的未处理异常
附加信息:调用线程无法访问此对象,因为其他线程拥有它。
Dispatcher dispatcher = Dispatcher.CurrentDispatcher;
thread = new Thread(() => ClientStart(dispatcher));
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
private void ClientStart(Dispatcher dispatcher)
{
....
Run Code Online (Sandbox Code Playgroud)
并更改了打印方法:
dispatcher.BeginInvoke(DispatcherPriority.Input, new …Run Code Online (Sandbox Code Playgroud) 当我运行命令时,git clone -v [repo]它会
接收对象:24%
并且永远挂起。我已经取消并重新尝试了大约 1/2 次,每次达到不同的百分比并挂起。我已禁用我的 AVG 防火墙无济于事。使用 Windows Server 2012 Git bash 版本 1.9.4
我需要运行任务以检查连接。
在此检查期间,不应冻结我的窗户。
因此,我启动了任务,并在此任务结束时关闭了窗口。
但这会返回一个异常:InvalidOperationException:“调用线程无法访问该对象,因为另一个线程拥有它”。
像这样 :
private void Window_ContentRendered(object sender, System.EventArgs e)
{
Task.Run(() =>
{
ConnectionState = false;
if (NetworkTools.CheckGlobalConnection() == (ConnectionStatus.NetworkConnectionSuccess, ConnectionStatus.ServerConnectionSuccess))
{
ConnectionState = true;
}
this.Close();
});
}
Run Code Online (Sandbox Code Playgroud)
如何在任务结束时关闭窗口而不冻结它且没有此异常?(我有一个无限旋转的进度条)
freeze ×10
c# ×2
java ×2
wpf ×2
clone ×1
debugging ×1
delphi ×1
delphi-xe2 ×1
dispatcher ×1
git ×1
if-statement ×1
indy ×1
indy10 ×1
javascript ×1
jquery ×1
particles ×1
ruby ×1
sprite ×1
sprite-kit ×1
task ×1
windows ×1