URL监视器不断增加内存使用量(URL monitor keeps increasing memory usage)
我使用.net 4.0编写了一个vb的URL监控程序。 基本上它设置一个计时器使用htpwebreques / httpwebresponse每60分钟检查一次URL,并在URL关闭时发送电子邮件。 但是,每次检查url时,应用程序使用的内存都会不断增加。 这显然最终会导致一个问题,因为该应用程序旨在永久监控网站的可用性,并且监控机器最终将耗尽资源。
代码为我的CheckURL例程下面。 任何建议非常感谢,提前感谢。
Private Sub checkURL() Timer1.Stop() Dim wReq As HttpWebRequest Dim wResp As HttpWebResponse ' WebResponse wReq = HttpWebRequest.Create(url) wReq.Method = "HEAD" Try wResp = wReq.GetResponse() If wResp.StatusCode = 200 Then txtResponse.Text = wResp.StatusCode & ": " & wResp.StatusDescription & vbNewLine & "The " & siteName & " is up" 'Only send success results if specified If sendOnFailure = False Then sendResults = True End If Else txtResponse.Text = "There may be a problem with the " & siteName & vbNewLine & "Please verify manually that it is operational." & vbNewLine & "The response received was:" & vbNewLine & "Status Code: " & wResp.StatusCode & " - " & wResp.StatusDescription sendResults = True End If wResp.Close() wResp = Nothing wReq = Nothing Catch ex As Exception txtResponse.Text = "There may be a problem with the " & siteName & vbNewLine & "The error returned was:" & vbNewLine & ex.ToString sendResults = True End Try txtLastCheck.Text = Now.ToString("d MMM yyyy HH:mm") setNextCheck() End Sub
I have written a URL monitoring program in vb using .net 4.0. Basically it sets a timer checks the url every 60 minutes using an htpwebreques/httpwebresponse and sends an email if the url is down. However the memory used by the application keeps increasing every time the url is checked. This will obviously eventually cause a problem as the app is designed to run permanently monitoring a website for availability and the monitoring machine will eventually run out of resources.
Code for my CheckURL routine below. Any advice greatly appreciated, thanks in advance.
Private Sub checkURL() Timer1.Stop() Dim wReq As HttpWebRequest Dim wResp As HttpWebResponse ' WebResponse wReq = HttpWebRequest.Create(url) wReq.Method = "HEAD" Try wResp = wReq.GetResponse() If wResp.StatusCode = 200 Then txtResponse.Text = wResp.StatusCode & ": " & wResp.StatusDescription & vbNewLine & "The " & siteName & " is up" 'Only send success results if specified If sendOnFailure = False Then sendResults = True End If Else txtResponse.Text = "There may be a problem with the " & siteName & vbNewLine & "Please verify manually that it is operational." & vbNewLine & "The response received was:" & vbNewLine & "Status Code: " & wResp.StatusCode & " - " & wResp.StatusDescription sendResults = True End If wResp.Close() wResp = Nothing wReq = Nothing Catch ex As Exception txtResponse.Text = "There may be a problem with the " & siteName & vbNewLine & "The error returned was:" & vbNewLine & ex.ToString sendResults = True End Try txtLastCheck.Text = Now.ToString("d MMM yyyy HH:mm") setNextCheck() End Sub
原文:https://stackoverflow.com/questions/41361023
最满意答案
你在
onCreateOptionsMenu
尝试这样@Override public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.menu_search_view_explore_ideas, menu); SearchView searchView = (SearchView)menu.findItem(R.id.action_search).getActionView(); searchView.setMaxWidth(Integer.MAX_VALUE);
you try like this in your
onCreateOptionsMenu
@Override public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.menu_search_view_explore_ideas, menu); SearchView searchView = (SearchView)menu.findItem(R.id.action_search).getActionView(); searchView.setMaxWidth(Integer.MAX_VALUE);
相关问答
更多-
搜索视图工具栏关闭图标(Search view toolbar close icon)[2022-07-30]
你在onCreateOptionsMenu尝试这样 @Override public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.menu_search_view_explore_ideas, menu); SearchView searchView = (SearchView)menu.findItem(R.id ... -
在工具栏中添加一个图标(Add a icon in the toolbar)[2022-04-01]
将Toolbar设置为支持ActionBar后,可以以编程方式设置它: ActionBar actionBar = getSupportActionBar(); if(actionBar != null) { actionBar.setDisplayShowHomeEnabled(true); actionBar.setIcon(R.drawable.your_image); } You can set it programmatically after you set your Tool ... -
在点击工具栏中更改图标(Changing icon in Toolbar on click)[2022-05-16]
只需调用setIcon()方法setIcon() 。 在你的情况下, item.setIcon(your drawable) Just call the method setIcon(). in your case, item.setIcon(your drawable) -
最后通过更改plugin.xml文件中视图的id来解决问题。
为什么工具栏中的“菜单”图标未显示在DrawerLayout中(Why is Menu icon in toolbar not appearing in DrawerLayout)[2023-06-11]
您的toolbar引用未初始化,因为Toolbar mToolbar是一个本地变量,因为您在添加当前未初始化的toogle使用toolbar引用而无效 改变这个 private void initToolbar() { Toolbar mToolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(mToolbar); setTitle(getString(R.string.app_n ...不完全是我想要的,但listview.setEmptyView(R.id ....)帮助了我。 Not exactly what i wanted, but listview.setEmptyView(R.id....) helped me.在你的Fragment中,在onCreateView()方法中,你必须添加: setHasOptionsMenu(true); 否则永远不会调用onCreateOptionsMenu() 。 In your Fragment, in the onCreateView() method, you have to add: setHasOptionsMenu(true); Otherwise the onCreateOptionsMenu() is never called.用图标替换工具栏标题(Replacing toolbar title by icon)[2023-08-12]
那么,您需要自定义您的toolbar :如下所示:试试这段代码 @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManife ...相关文章
更多- 转 Apache Mod cache usage and configuration
- elixir usage
- 13年7月memory point
- Spark - A Fault-Tolerant Abstraction for In-Memory Cluster Computing
- CLR Via C# 3rd 阅读摘要 -- Chapter 21 – Automatic Memory Management (Garbage Collection)
- 关于mysql数据库memory表数据重复问题
- POJ 3620 Avoid The Lakes【DFS水题练格式Avoid The Lakes Time Limit: 1000MS Memory Limit: 65536K Total Sub】
- Heritrix源码分析(十一) Heritrix中的URL--CandidateURI和CrawlURI以及如何增加自己的属性(转)
- Solr Performance Factors(Solr 性能因素)
- jstl c:url教程-jstl输出url标签
最新问答
更多- 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
- 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
- OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
- 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
- codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
- 在计算机拍照在哪里进入
- 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
- No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
- 单页应用程序:页面重新加载(Single Page Application: page reload)
- 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
- System.StackOverflow错误(System.StackOverflow error)
- KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
- 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
- android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
- TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
- 企业安全培训的各项内容
- 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
- C#类名中允许哪些字符?(What characters are allowed in C# class name?)
- NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
- 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
- 将多个行和可变行移动到列(moving multiple and variable rows to columns)
- 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
- 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
- Angular $资源不会改变方法(Angular $resource doesn't change method)
- 在Angular 5中不是一个函数(is not a function in Angular 5)
- 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
- 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
- 常见的python rpc和cli接口(Common python rpc and cli interface)
- Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
- 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)